Links

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
else
else if
while
do while
for
break
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 which has a value. Such as a function call which returns a value, a variable, a mathematical sum. literal values and comparisons.
In computer programming languages, a Boolean is a data type with only the 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 commands brackets is TRUE, then the code nested within it is executed, as shown below
main {
if (TRUE) {
// This will always run as the condition above is always true
}
if (FALSE) {
// This will never run as the condition above is never true
}
}
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
main {
if (FALSE) {
// This will never run as the condition above is never true
}
else {
// This will run as the result of the previous condition never
// is true
}
}
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 above text!
main {
if (FALSE) {
// This will never run as the condition above is never true
}
else if (TRUE) {
// This will run as the result of the previous condition never
// is true but the condition here is always true
}
}
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
int a;
main {
while (a < 10) {
// Do something while a is less than 10
}
}
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
int a = 0;
main {
while (a != 0) {
// This will never execute as a is already 0
}
do {
// This will be executed once, then the condition will be checked
// to see if we should run the block again
} while (a != 0);
}
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:
for ( < initalizer > ; < condition > ; < increment >)
See the below example for how it could be used
int a;
main {
for (a = 0; a < 10; a++) {
// Whatever you put here will be run 10 times
}
}
The break command is used to end a loop early based on a condition, see below for an example
int a;
main {
while (TRUE) {
if (a == 0) {
// We want to end the loop if the variable a has a value of 0
break;
}
}
}