Basic GPC Structure
A GPC script can be split into sections. There can be a total of 9 different sections and, in any user-made script, they should be laid out in the order shown in the example below. Only the main section is mandatory as it is the heart of any script and is run in a constant loop.
The define is used to assign a value to a word, creating a named constant. Definitions can be placed anywhere except inside the init, main, a combo, or function.
In this example, we define zero, one, and two as the values 0, 1, and 2 respectively. These are static values that cannot be altered during run time. So, should we use the word 'one' at any point in the script it is the same as typing the number 1.
For more detailed information, check out the Definitions page.
The data section is an array of bytes (8-bit integer) that is placed at the start of the Virtual Address Space in GPC bytecode. The values are read-only and cannot be altered at run time. The user can access these values via the zero-based data array.
For example in this script we could do this to access the array:
For more detailed information, check out the Data Section page.
The const array section is similar to the data section, except it's easier to manage as you let the compiler track where the data is stored - under the hood it uses the data section, but in a different way.
Const arrays consist of 2 different types, one dimension and multi-dimensional - the difference between them is how the data is structured/accessed, see below for how they're defined:
For more detailed information, check out the Const Arrays page.
In this section, we can alter the behavior of the controls with remap. In this example, we are telling the Virtual Machine that a value assigned to the Left Bumper should be sent to the Right Bumper instead and vice versa.
It is important to note that button remaps are applied once the main has finished and just before the output report is sent to the console. This means scripting should be programmed without considering the remapping.
For example, if at some point in this script we were to set the Left Bumper to 100 like so:
When the main procedure finishes, the output report would initially contain a value of 100 for the Left Bumper. When the remaps are processed, this value would then instead be assigned to the Right Bumper and the output report would be modified. When the final output report is sent to the console, it would contain a value of 100 for the Right Bumper instead of the Left.
For more detailed information, check out the Remapping page.
A variable is a point in the stack memory where a value can be placed anywhere except inside of the main{} combo{} or function(). These variables are global and GPC and can be accessed at any point within the script. Variables are not static and can be altered during run time.
If a variable is not assigned a value in this section, it is initialized with the value 0. Such as the variables example2 and example3 in this script:
For more detailed information, check out the Variables page.
The init section is similar to main with the exception that it is only run once when the script is loaded into the virtual machine.
It can run the same commands and functions as the main section such as combos and user-created functions. It is generally used to populate variables and arrays to set up the script. In this example, if the Cronus Zen has a PS4 controller connected when the script is first loaded, example2 is assigned a value of 27. Otherwise, it is assigned a value of 1.
For more detailed information, check out the Init Section page.
The main section is the heart and soul of any GPC script, all functions and combos are initially executed from this section. It is the only mandatory section and every GPC script must have one.
Unlike combos and user-created functions, a GPC may only have one main section and it is run in a loop.
The Virtual Machine runs through the code in order and generates an output report as it goes. When the Virtual Machine gets to the end of the main section, the output report is then ready to be sent to the console. Once the console requests new data, the output report is sent and the main starts another run.
As commands are run through in order, setting the value of a button in more than one place means that only the last command is sent.
For example, in this script, a value of -100 for the LY axis will be sent to the console. The console will not see the LY axis set to 100 because the output report for that control is modified again before it is sent to the console.
For more detailed information, check out the Main Section page.
A combo is a function that will perform a set of instructions in order and for the amount of time assigned to the wait command directly after the commands.
In this script, when the combo is run, it will set identifier 20 (X on an Xbox controller or Square on a PlayStation controller) to 100% (Fully pressed) for the time set in the variable example1 (10 milliseconds in this case) and then do nothing for 100 milliseconds.
You can assign multiple commands before a single wait statement. For example, in the following combo, both the Left Bumper and Right Trigger will be pressed for 500 milliseconds (half a second) when the combo is run. It will then do nothing for 500 milliseconds.
For more detailed information, check out the Combo Section page.
A user-created function is similar to the main section. Commands are processed in order and any GPC which is valid in the main section can be used here. Functions must be placed at the end of the GPC script.
The main difference with functions is they are only run when called and can return a value. When a value is returned from a function, it is terminated and any code beyond that point is not executed.
GPC user functions are global, this means that can be called from the init, main and combo sections. A function can even be called from within another function.