Main Section
The main section is the heart and soul of any GPC script. It is run in a constant loop from the top down and any code executed during run time can be traced back to it. Therefore, the main section is mandatory and a GPC script is not valid without one. Just as with any nested code, the main section start and finish points are denoted with a { or } respectively, like so;
When the main section reaches the endpoint, the output report to the console is created, any remaps are evaluated and the report is sent to the console. The main section is then restarted from the beginning.
The code within the main section is executed in the order it is written. It is important to remember this when building your own GPC scripts as the output report to the console is created at the end of the main section, so it is possible to create code that would cancel each other out and result in a different output to the console than you expected. For example;
As you can see above, the variable 'hold_lt' is set to TRUE when the RT/R2 button is pressed but is immediately set to FALSE in the next line of code. Therefore the if(hold_lt) statement will always be FALSE and the code nested within the if statement will never be executed.
However, if we were to move the code around, then we would get the expected output.
If RT/R2 is pressed then hold_lt is set to TRUE after it has been set to FALSE, the if(hold_lt) statement will see that it is TRUE and the nested code will be run. If RT/R2 isn't being pressed then 'hold_lt' is not set to TRUE after it has been set to FALSE and the nested code is not run.
So, as you can see in the above examples, it is important to remember that code is executed in the order it is written and simply moving the placement of a line can have a significant effect on the output to the console.