If I declare a variable or a function in the autonomous section, can I use it in the driver control
period, or is it out of scope? If it is out of scope, then where can I declare it so that it will be in scope globally?
If you have something in a function in your autonomous code that asks if a button is being pressed, will just always be false during auton, or will it return an error?
Can someone direct me to some good sources on how to code for pneumatics?
Will these two lines produce the same results?
Rmotor1.spin(vex::directionType::fwd, -x , velocityUnits::pct);
Rmotor1.spin(vex::directionType::rev, x, velocityUnits::pct);
Below is an example of code with variables declared in different scopes.
// A global instance of competition
competition Competition;
//This variable is available to all functions.
int globalVar = 456;
void autonomous(void) {
int autonOnly = 123; //only available inside this function.
if(globalVar == 456){
//Successful access to variable outside of autonomous scope
}
if(driverOnly == 789){
//Error: Undeclared.
}
}
void usercontrol(void) {
int driverOnly = 789;
while (1) {
if(globalVar == 456){
//Successful access to var outside of user control scope
}
if(autonOnly == 123){
//Error: Undeclared.
}
wait(20, msec);
}
}
Image of Code Above
You will notice that the editor has a red underscore on the variables with an error. It is warning the programmer that it is Undeclared (or cannot find it).