|
Re: Variable Scope
WPILib will automatically break the program out of Autonomous() when the operator control period starts. Even if you have an infinite loop in your autonomous function it will put you into the OperatorControl() function when the autonomous period ends. It will not break you out of the Initialize() function which is where you probably want to be initializing things like cameras, gyros, etc.
The variable scoping is just as you described and follows normal C rules. However those variables declared as locals in the Autonomous(), OperatorControl() or Initialize() functions will not be available to each other or to other functions (unless passed as arguments).
To make variables that are available between functions they need to be global in scope - declared outside of any functions. And you need extern declarations for them somewhere, probably in a header file.
Also, you should not put anything in the main function for a competition program - but an empty main function needs to be there to satisfy a linker requirement.
__________________
Brad Miller
Robotics Resource Center
Worcester Polytechnic Institute
|