Basic Syntax

The basic syntax of a GPC script.
define Cronus = 120;
int ZEN = 100;
main {
if (get_val(XB1_A)) {
combo_run(jump);
}
}
combo jump {
set_val(XB1_A, 100);
wait(Cronus);
set_val(XB1_A, 0);
wait(ZEN);
}

Instruction Separation

As in C, GPC requires instructions to be terminated with a semicolon at the end of each statement. However, the closing tag of a block code automatically implies a semicolon, so a semicolon is not needed when terminating the last line of a GPC block.

main {
sensitivity(XB1_LY, NOT_USE, 80);
a = b * ( c + 20 )
}

Although the semicolon is not required in the final line of a block, it is considered good practice to use one so it is not missed should you expand on the code at a later date.

Nesting Code

Nesting code, or creating a logic block, binds code together. A Block starts with a { and end with a }. What this does is nest the code with the { and } meaning that the code is only executed when the statement before it is active.

main
{ //Main Start
if(get_val(PS4_R2))
{ //Block 1 Start
if(get_val(PS4_L2))
{ //Block 2 Start
combo_run(RAPID_FIRE_ADS);
} //Block 2 End
else
{ //Block 3 Start
combo_run(RAPID_FIRE);
} //Block 3 End
} //Block 1 End
} //Main End

In this example, Blocks 2 & 3 are ignored unless Block 1 is active.

So if the R2 button is not pressed, nothing happens. If R2 is pressed, then the CronusMAX looks at Block 2. If L2 is pressed, it will run the combo RAPID_FIRE_ADS and ignore Block 3. However, if L2 is not pressed, it will ignore Block 2 and instead execute the code in Block 3 and then run combo RAPID_FIRE.

Nesting is implied if you only have one line of code after a statement. As in this example;

main {
if(get_val(XB1_RT) > 95)
combo_run(RAPID_FIRE);
}

When compiled, the line combo_run(RAPID_FIRE); will automatically be nested within the if statement. If you wish for more than one line of code to only be executed when the statement before them is active, then you must use { and }.

Commenting Code

A comment is text which is ignored by the compiler. Comments are usually used to annotate code for future reference or to add notes for others looking at the code. However, they can also be used to make certain lines of code inactive to aid when debugging scripts. If you have programmed in C before then GPC comments will be familiar to you as it uses the same style.

There are two types of comments, the Single Line Comment and the Multi Line Comment.

Single Line Comment

The // (two slashes) characters creates a single line comment and can be followed by any sequence of character. A new line terminates this form of comment. As shown below

main {
// A single line comment
if(get_val(XB1_RT) > 95)
// Another single line comment
combo_run(RAPID_FIRE);
}

Multi Line Comment

The / (slash, asterisk) characters starts a multi line comment and can also be follow by any sequence of characters. The multi line comment terminates when the first / (asterisk, slash) is found. As shown below

main {
/* A multi line comment
if(get_val(XB1_RT) > 95)
combo_run(RAPID_FIRE);
*/
}

As the comment terminates when a */ (asterisk, slash) is found, this style of commenting cannot be nested. As shown below

main {
/* A multi line comment
if(get_val(XB1_RT) > 95)
combo_run(RAPID_FIRE); /*This will cause a problem*/
*/
}