Using Integer variables

Can anyone show me an example of how to setup an integer variable in the BuiltinDefaultCode example?

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?

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.

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.

I think you want to be saying

if (x == 1) { ...

rather than the single equal sign, which is an assignment operator, not a conditional.