Several Programming Questions

note: I am using vex code v5 pro

  1. 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?

  2. 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?

  3. Can someone direct me to some good sources on how to code for pneumatics?

  4. Will these two lines produce the same results?
    Rmotor1.spin(vex::directionType::fwd, -x , velocityUnits::pct);
    Rmotor1.spin(vex::directionType::rev, x, velocityUnits::pct);

  1. I think we need more context for this. What exactly are you trying to do?

  2. Sounds like something easy to test and find out!

  1. Use the search bar.

  2. They should. Also sounds like something easy to test and find out!

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).
image