The main structure is where the project execution begins. In other words, instructions containing devices, commands, and parameters are added here, the combination of which, when executed, determine specific robot behaviors.
Notice that the main structure has an opening and closing curly brace:
An opening brace must always be paired with a closing brace.
Between the curly braces of the main structure is where you can add instructions to program your robot:
Whenever you start a new program, inside the main structure is the line of code
This command sets up and initializes all devices (e.g. motors, sensors) before your code begins. Do not delete the
In a simple project that drives the robot forward, the instruction contains three sections:
- The device
- The command
- The parameters
The device and the command are separated by a period called a “ dot operator”:
Around the parameters of the driveFor command, there is a set of parenthesis. This is another example of paired punctuation (like the curly brace). Each parameter is separated by a comma.
At the end of the line of code is a semicolon. The semicolon tells the compiler that this instruction is complete and should proceed to the next instruction.
If multiple instructions are in your project, the project’s instructions will run from left to right and top to bottom.
Based on the placement of the semicolons, VEXcode Pro V5 would run the first line and then the next. It would know to move to the second line because of the semicolon.
When the project reaches the closing curly brace of the main structure, the project ends.
In the project below the robot would drive forward for 200 millimeters (line 24), then drive the robot forward 50 millimeters (line 25) before the program is complete.