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.

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 analyse 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

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

As explained here, 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.

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.

{
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. More information on nesting code can be found here.

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

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 which 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.

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.

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. Additional detail on how a combo operates can be found here.

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:

if(get_val(XB1_RT)){

and change it to:

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

By introducing && !get_val(XB1_LT) in to 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'. Which 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.