robotc

Integers and scopes


If I declare integers before task main() in ROBOTC those integers would be in the global scope? Therefore, I would be able to call them out at any time; however, I plan to create other tasks and void functions before my task main(). Would the integers I create, their placement would have to be directly underneath the pragma statements?

#pragma  config(Motor, mtr_S1_C1_1, motorRight, tmotorNormal, PIDControl)
#pragma config(Motor, mtr_S1_C1_2, motorLeft, tmotorNormal, PIDControl)

/* Initialized Integer Placement*/

task main(){
motor[motorLeft] = 50; // Half power
motor[motorRight] = 50;
wait1Msec(1000); // One second
motor[motorLeft] = 0; // Stop
motor[motorRight] = 0;
}

Solution

  • Yes, they would be globals, which you can use in any of your functions. Be careful not to create any local variables inside your functions by the same name as it could cause problems.