Flow Control

Command
Description
Zen
Plus

if

Executes a block of code if the condition is met

✔️

✔️

else

Executes a block of code if the previous if condition is not met

✔️

✔️

else if

Executes a block of code if the previous if condition is not met but the current condition is met

✔️

✔️

while

A loop that runs while a condition is met

✔️

✔️

do while

A loop that runs at least once

✔️

✔️

for

A loop that runs a set amount of times

✔️

✔️

break

Breaks out early while in a loop

✔️

✔️


if

The if command is one of the single most useful tools for your GPC scripting needs. It allows you to control when certain blocks of code are run and it takes any expression, function, or code which returns or has a value. It can also be used in the init, main, combo, and function sections of your code.

The if command works by evaluating the expression within it to its boolean value. An expression is anything that has a value, such as a function call that returns a value, a variable, or a mathematical sum, literal values and comparisons.

In computer programming languages, a boolean is a data type with only two possible values, true or false. In GPC, false means 0 and true is a value other than 0, be it a negative or positive value.

If the expression placed within an if command's brackets is true, then the code nested within it is executed. If the expression is false and an else block is present, that block is executed instead:

As shown below:


else

Should you wish to execute a different block of code when an if command does not return true then you would use the else command. An else command must have an if command preceding it. The code block contained within an else command will be executed if the expression in the if statement returns false, as shown below:


else if

else if is a combination of else and if. Just like the else command it allows for a different block of code to be executed when the statement within the if command returns false. However, it will only execute the code block when the statement within its parameter returns true.

For example, if you were playing a first person shooter game and wished for rapid fire to be disabled when you aim down the sights but wanted the Cronus Zen to automatically hold breath in the game to steady your aim while aiming down the sights, the following code would do this for you:

Note: Example below is more of a "how it works", needs to be updated with one reflecting the above text!


while

The operation of the while command is straight forward, it will execute code nested within it until the expression contained in its parameter is no longer true.


do while

do while is similar to while in that it runs a block of code while a condition is true, the difference is that it executes the block at least once, see below for an example:


for

The for loop can be used to run a block of code for a set amount of times, the syntax for using it is as follows:

See the below example for how it could be used:


break

The break command is used to end a loop early based on a condition, see below for an example:

Last updated