View Full Version : Using Integer variables
programmr
13-02-2009, 13:45
Can anyone show me an example of how to setup an integer variable in the BuiltinDefaultCode example?
Alan Anderson
13-02-2009, 13:55
In general, it's as easy as saying int varname;
replacing varname with the name you want to use. The proper place to put that line depends on what you want to use the variable for.
What do you want to use the variable for?
programmr
14-02-2009, 13:07
yes, where to put the variable seems to be our problem. we want to use the variable to keep track of the state of one of our joystick buttons in teleop mode.
int x;
//Now later in the program during teleop routines
if (rightStick->GetRawButton(2)) {
if x = 1 {
x=0; }
else {
x=1; }
x could then be examined to determine the speed of our motors.
Sentient
14-02-2009, 17:00
Where to put x is called scope. If you want x available throughout teleop mode (but you don't need it anywhere else), you can put it directly after OperatorControl(){
You may want to do some more research into scope though. It is an important concept to master.
Rick Wagner
14-02-2009, 17:26
yes, where to put the variable seems to be our problem. we want to use the variable to keep track of the state of one of our joystick buttons in teleop mode.
int x;
//Now later in the program during teleop routines
if (rightStick->GetRawButton(2)) {
if x = 1 {
x=0; }
else {
x=1; }
x could then be examined to determine the speed of our motors.
I think you want to be saying
if (x == 1) { ...
rather than the single equal sign, which is an assignment operator, not a conditional.
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.