Conditional If/Else
Simple conditional branches for flow control.
The if/else section is the simplest and most common section, allowing branches in code based on certain conditions.
It forms a tree structure of possible branches.
1
if %Boolean%:
2
// branch 1
3
else if %Boolean%:
4
// branch 2
5
else:
6
// branch 3
Copied!

If Block

These must always start with an if effect as the section header.
1
if "hello" is a string: // the (... is a string) expression = true
2
print "yes"
Copied!
If the boolean value in the if %Boolean% is true, the section under the if clause will be run.
Instead, if the condition fails, that section will be skipped.
1
if 1 is a string: // fails
2
print "yes" //
3
print 1 // this will not be run
4
print "no" // skips to here
Copied!
This can be used as an inline section as well.
1
if "hello" is a string: // fails
2
print "yes"
3
if 1 is 2 // skips to the end of this block
4
print "uh oh... maths is wrong" // this will never happen
5
print "finished" // skips to here
Copied!
That second inline if ... will skip to the end of the current code section, or to the end of the trigger if there is no indent.

Else If Block

An if-block may be followed by an else-if block. This will be run if the condition is met, like the if section.
1
if 1 is 2: // fails
2
print "no"
3
else if 1 is 1: // tries this next
4
print "yes"
Copied!
If the preceding conditional section passes, the else if... will be skipped.
1
if 1 is 1: // passes
2
print "yes"
3
else if 1 is 1: // skipped
4
print "never run"
Copied!
An else if... may not be used on its own. It must have either an if... or another else if... directly before it.
1
if 1 is 3: // fails
2
print "never run"
3
else if 1 is 2: // fails
4
print "never run"
5
else if 1 is 1: // run
6
print "yes"
7
else if 1 is 1: // skipped
8
print "never run"
Copied!
After a match is found in an if/else tree, all following sections will be ignored.

Else Block

An if/else tree may be finished with one else block. This does not accept a condition, and runs if none of the preceding conditions passed.
1
if 1 is 3: // fails
2
print "never run"
3
else: // run
4
print "yes"
Copied!
The else block will not be run if a preceding condition passes instead.
1
if 1 is 2: // fails
2
print "never run"
3
else if 1 is 1: // passes
4
print "yes"
5
else: // skipped
6
print "never run"
Copied!

Special Behaviour

Multiple conditions can be stacked on one section using a combination of inline and block headers.
1
if 1 is 1: // passes
2
print "yes"
3
if 1 is 2 // fails -> moves to the else
4
print "never run"
5
else: // run
6
print "this is run!!!"
Copied!
This allows multiple conditions to be linked to the same branch of the tree to allow for more complex behaviour.
1
if 1 is 1: // passes
2
if true // passes
3
if 1 is 2 // fails -> moves to the else
4
print "never run"
5
else: // run
6
print "this is run!!!"
Copied!
This behaviour is different from original Skript.