Basic GPC Structure

A GPC script can be split into sections. There can be a total of 8 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.

Definitions
Data
Remapping
Variables
GPC Init
GPC Main
Combo
Function
Definitions

Definitions Section

// Definitions Section (OPTIONAL)
define zero = 0;
define one = 1;
define two = 2;

The definition section is used to assign values to words thus creating a named constant. Definitions must be placed before the main section.

In this example we define zero, one and two to the values 0, 1, 2 respectively. These are static values which 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.

Data

Data Section

// Data Section (OPTIONAL)
data (zero, one, two, 10, 128, 40);

The data section is an array of bytes (8 bit unsigned integer) which 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:

example4 = dbyte(4); //example4 = 128

Remapping

Remapping Section

// Remapping Section (OPTIONAL)
remap XB1_LB -> XB1_RB;
remap XB1_RB -> XB1_LB;

In this section we can alter the behavior of the controls. In this example we are telling the Virtual Machine that an 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:

set_val(XB1_LB, 100);

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.

Variables

Variable Initialization Section

// Variable Initialization Section (OPTIONAL)
int example1 = 10;
int example2, example3;
int example4 = 17;

This is where the user can create variables. A variable is a point in the stack memory where a value can be placed and they can only be created before the main or init sections. 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.

GPC Init

GPC Initialization Section

// GPC Initialization Section (OPTIONAL)
init {
if(get_controller() == PIO_PS4){
example2 = 27;
} else {
example2 = 1;
}
}

The init section is similar to the main with the exception that it is only run once when the script is loaded in to 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/arrays and 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.

GPC Main

GPC Main Section

// GPC Main Section (MANDATORY)
main {
if(example_function()){
if(get_val(example3)){
combo_run(testing);
}
}
}

The main section is the heart and sole of any GPC script, all functions/combos are initailly executed from this function. It is the only mandatory section and every GPC must have one. Unlike combos and user created functions, a GPC may only have one main section. 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:

main {
set_val(XB1_LY, 100);
set_val(XB1_LY, -100);
}

A value of -100 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.

Combo

Combo Section

// Combo Section (Optional)
combo testing{
set_val(20, 100);
wait(example1);
wait(100);
}

A combo (which is short for Combination) 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.

combo LB_AND_RT {
set_val(XB1_LB, 100);
set_val(XB1_RT, 100);
wait (500);
wait (500);
}
Function

Function Section

// Function Section (Optional)
function example_function(){
if(get_val(example2)){
example3 = 18;
return 1;
} else if(get_val(example4)){
example3 = 19;
return 1;
}
return 0;
}

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 of a 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, the function 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.

Putting it all together

// Definitions Section (OPTIONAL)
define zero = 0;
define one = 1;
define two = 2;
// Data Section (OPTIONAL)
data (zero, one, two, 10, 128, 40);
// Remapping Section (OPTIONAL)
remap XB1_LB -> XB1_RB;
remap XB1_RB -> XB1_LB;
// Variable Initialization Section (OPTIONAL)
int example1 = 10;
int example2, example3;
int example4 = 17;
// GPC Initialization Section (OPTIONAL)
init {
if(get_controller() == PIO_PS4){
example2 = 27;
} else {
example2 = 1;
}
}
// GPC Main Section (MANDATORY)
main {
if(example_function()){
if(get_val(example3)){
combo_run(testing);
}
}
}
// Combo Section (Optional)
combo testing{
set_val(20, 100);
wait(example1);
wait(100);
}
// Function Section (Optional)
function example_function(){
if(get_val(example2)){
example3 = 18;
return 1;
} else if(get_val(example4)){
example3 = 19;
return 1;
}
return 0;
}