> For the complete documentation index, see [llms.txt](https://guide.cronuszen.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://guide.cronuszen.com/gpcscripting/gpc-script-guide/gpc-developer-guide/a-simple-tutorial.md).

# A Simple Tutorial

### Step 1

* Load Zen Studio and click **File > New > Empty File**.

### Step 2

* Copy and paste the following code into the GPC Code Editor within Zen Studio:

```gpc
main {
    if(get_val(XB1_RT)) {
        combo_run(rapid_fire);
    }
}

combo rapid_fire {
    set_val(XB1_RT, 100);
    wait(40);
    set_val(XB1_RT, 0);
    wait(30);
    set_val(XB1_RT, 0);
}
```

### Step 3

Compile the code to check for errors. To do this, either press **F7** on your keyboard or go to the **Compiler** drop down menu in Zen Studio and select **Compile**.

The output window below the GPC editor should give you this message:

```
GPC Build Started
1 New Compilation Completed with 0 Warning(s)
Total Byte Size: 148 Bytes (0.23%)
Total Variables Used: 3 of which 3 are dedicated to Combos (0.59%)
```

If your Cronus Zen is connected via the PROG USB port and you have a controller connected, you can see this script in action by using the **Build and Run** option. This is accessed by either pressing **F5** or selecting **Build and Run** in the **Compiler** drop down menu. This function will compile the code and then send it to your Cronus Zen so you can test it.

***

### Script Breakdown

What this script does is run the combo named `rapid_fire` whenever the right trigger has a value or is pressed. If the right trigger is still held when the combo ends, it will be run again.

To analyze how the Cronus Zen is told how to do this we must first break the script down into its two sections, the **main** and **combo** sections.

#### The Main Section

```gpc
main {
    if(get_val(XB1_RT)) {
        combo_run(rapid_fire);
    }
}
```

The `main` section is run in a loop by the Cronus Zen. The virtual machine in the Cronus Zen runs through the code in order and when it reaches the end of the code, data is sent to the console and then the virtual machine starts the next loop.

```gpc
if(get_val(XB1_RT))
```

The above code tells the Cronus Zen that if the statement is true, run the nested code. In this case, if `XB1_RT` (right trigger) has a value greater than 0 (zero), so is pressed or not at rest.

```gpc
{
    combo_run(rapid_fire);
}
```

Above is the code nested within the `if` statement. Nesting code creates a hierarchical structure. An open curly bracket `{` starts the nesting and a closed curly bracket `}` ends it. By nesting code within the `if` statement, we are telling the Cronus Zen that we only wish for that code to be executed only when the `if` statement is true.

```gpc
combo_run(rapid_fire);
```

This line simply tells the Cronus Zen to run the combo named `rapid_fire`. It is important to note that if the Cronus Zen receives this instruction and the combo is already running, it will not do anything. It will only run the combo again if it has finished.

This means that if you hold down the right trigger with this code active, the Cronus Zen start the combo and then run it again as soon as it has ended — therefore, running the combo in an indefinite loop or until such time as the right trigger is released.

#### The Combo Section

```gpc
combo rapid_fire {
    set_val(XB1_RT, 100);
    wait(40);
    set_val(XB1_RT, 0);
    wait(30);
    set_val(XB1_RT, 0);
}
```

This is the combo that the Cronus Zen is instructed to run when the right trigger is pressed. When run, a combo runs through the code until it gets to a `wait` statement. The `wait` statement instructs combo to execute the commands above it for a set amount of time which is expressed in milliseconds.

```gpc
set_val(XB1_RT, 100);
wait(40);
```

These lines instruct the combo to set the value of the right trigger to 100 (or fully pressed) for 40 milliseconds.

```gpc
set_val(XB1_RT, 0);
wait(30);
```

Once the 40 milliseconds has passed, these lines instruct the combo to set the right trigger to 0 (release) for 30 milliseconds.

***

### Expanding the Code

Now that you understand how this script works, we will make it more complex and change when the combo is run.

Look at this line in the main section:

```gpc
if(get_val(XB1_RT)) {
```

And change it to:

```gpc
if(get_val(XB1_RT) && !get_val(XB1_LT)) {
```

By introducing `&& !get_val(XB1_LT)` into the `if` statement we are telling the Cronus Zen to only run the combo if the right trigger has a value **and** the left trigger does **not**.

`&&` means "and" in GPC and `!` means "not", so the `if` statement now reads: "if right trigger has a value **and** left trigger does **not**."

This means when using this code in game, the Cronus Zen will only rapid fire your gun when you are not aiming down the sights.

You can use the **Build and Run** function to see this code in action.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://guide.cronuszen.com/gpcscripting/gpc-script-guide/gpc-developer-guide/a-simple-tutorial.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
