---
title: Basic Syntax
slug: gpc/basic-syntax
description: Learn the basic syntax of a .gpc script in this document. Discover how to separate instructions and nest code using {}. Understand when and how to use semicolons and how commenting code can help annotate or deactivate lines. Explore the different types of
docTags: 
createdAt: 2021-12-04T12:27:42.000Z
---

This is basic syntax of a `.gpc` script:

:::CodeblockTabs
GPC

```apex
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.

:::CodeblockTabs
GPC

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

:::hint{type="info"}
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.

:::CodeblockTabs
GPC

```apex
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
```
:::

:::hint{type="info"}
In this example, Blocks 2 & 3 are ignored unless Block 1 is active.&#x20;

So if the R2 button is not pressed, nothing happens. If R2 is pressed, then the Cronus Zen 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;

:::CodeblockTabs
GPC

```apex
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 create a single line comment and can be followed by any sequence of characters. A new line terminates this form of comment. As shown below

:::CodeblockTabs
GPC

```apex
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 start a multi-line comment and can also be followed by any sequence of characters. The multi-line comment terminates when the first \*/ (asterisk, slash) is found. As shown below:

:::CodeblockTabs
GPC

```apex
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

:::CodeblockTabs
GPC

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

