Basic Syntax
The basic syntax of a GPC script.
1
define Cronus = 120;
2
int ZEN = 100;
3
4
main {
5
if (get_val(XB1_A)) {
6
combo_run(jump);
7
}
8
}
9
10
combo jump {
11
set_val(XB1_A, 100);
12
wait(Cronus);
13
set_val(XB1_A, 0);
14
wait(ZEN);
15
}
Copied!

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.
1
main {
2
3
sensitivity(XB1_LY, NOT_USE, 80);
4
a = b * ( c + 20 )
5
6
}
Copied!
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.
1
main
2
{ //Main Start
3
if(get_val(PS4_R2))
4
{ //Block 1 Start
5
if(get_val(PS4_L2))
6
{ //Block 2 Start
7
combo_run(RAPID_FIRE_ADS);
8
} //Block 2 End
9
else
10
{ //Block 3 Start
11
combo_run(RAPID_FIRE);
12
} //Block 3 End
13
} //Block 1 End
14
} //Main End
Copied!
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;
1
main {
2
if(get_val(XB1_RT) > 95)
3
combo_run(RAPID_FIRE);
4
}
Copied!
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
1
main {
2
// A single line comment
3
if(get_val(XB1_RT) > 95)
4
// Another single line comment
5
combo_run(RAPID_FIRE);
6
}
Copied!

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
1
main {
2
/* A multi line comment
3
if(get_val(XB1_RT) > 95)
4
combo_run(RAPID_FIRE);
5
*/
6
}
Copied!
As the comment terminates when a */ (asterisk, slash) is found, this style of commenting cannot be nested. As shown below
1
main {
2
/* A multi line comment
3
if(get_val(XB1_RT) > 95)
4
combo_run(RAPID_FIRE); /*This will cause a problem*/
5
*/
6
}
Copied!
Last modified 1yr ago