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
1
main {
2
if (TRUE) {
3
// This will always run as the condition above is always true
4
}
5
if (FALSE) {
6
// This will never run as the condition above is never true
7
}
8
}
Copied!
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
1
main {
2
if (FALSE) {
3
// This will never run as the condition above is never true
4
}
5
else {
6
// This will run as the result of the previous condition never
7
// is true
8
}
9
}
Copied!
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!
1
main {
2
if (FALSE) {
3
// This will never run as the condition above is never true
4
}
5
else if (TRUE) {
6
// This will run as the result of the previous condition never
7
// is true but the condition here is always true
8
}
9
}
Copied!
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
1
int a;
2
main {
3
while (a < 10) {
4
// Do something while a is less than 10
5
}
6
}
Copied!
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
1
int a = 0;
2
main {
3
while (a != 0) {
4
// This will never execute as a is already 0
5
}
6
7
do {
8
// This will be executed once, then the condition will be checked
9
// to see if we should run the block again
10
} while (a != 0);
11
}
Copied!
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
1
int a;
2
main {
3
for (a = 0; a < 10; a++) {
4
// Whatever you put here will be run 10 times
5
}
6
}
Copied!
The break command is used to end a loop early based on a condition, see below for an example
1
int a;
2
main {
3
while (TRUE) {
4
if (a == 0) {
5
// We want to end the loop if the variable a has a value of 0
6
break;
7
}
8
}
9
}
Copied!
Last modified 1yr ago
Copy link