If..Then..Else

Syntax

Command Description Return Value
If (<expression>) [Then] <action> [Endif] Tests expression and performs action if true The result of action
If (<expression>) [Then] <action1> Else <action2> [Endif] Tests expression and performs action1 if true or action2 if false The result of action1 or action2

Abbreviation

None

Description

The If .. Then .. Else statements are used to conditionally execute commands based on the value of an expression.

Consider this command:

If ('x' == 1) Then Cue 1 Go

The above example first checks the value of the variable x, and if it is equal to 1, then Cue 1 is executed. On the other hand, if x is not equal to 1, then nothing will happen. Since no commands are present after the “Cue 1 Go”, an EndIf is not necessary.

See the section on Expressions for more information about the kinds of expressions that can follow an If statement.


Using Else

The Else keyword can be used to execute commands if the expression is false. Consider this example:

If ('mode' > 5) Then Cue 1 Go Else Cue 2 Go

In the above example, if the value of mode is greater than 5, then Cue 1 will execute, but if mode is 4 or less, then Cue 2 will execute. Since no commands are present after the “Cue 2 Go”, an EndIf is not necessary.


Using Endif

In the basic form of the If .. Then statements, all of the commands after the Then will be executed if the expression is true. In the case where additional non-conditional commands are needed after the If .. Then statement, use the Endif keyword to end the conditional part of the If .. Then statement.

For example, in the following command, Cue 1 will execute and Playback 2 will be cleared if the showEnabled variable is 1:

If ('showEnabled' == 1) Then Cue 1 Go; Playback 2 Clear

But, by inserting the Endif keyword, the script can be changed to have Cue 1 execute only if the showEnabled variable is 1, but Playback 2 is always cleared:

If ('showEnabled' == 1) Then Cue 1 Go Endif Playback 2 Clear


Using Multiple Lines

The If .. Then .. Else statements can also be used across multiple lines of code, which is particularly useful when the script becomes more complex:

Playback 1

If ('testMode' == 1) Then
    Cue 1 Go
Else
    Cue 2 Go
EndIf

Playback 2 Clear

<hr>

Nesting Multiple If .. Then Statements

For more complex logic scenarios, you can put If .. Then statements inside of other If .. Then statements. For example:

Playback 1

If ('testMode' == 1) Then
    Cue 1 Go
Else
    If ('eStop' == 1) Then
        Cue 99 Go
    Else
        Cue 2 Go
    EndIf
EndIf

Playback 2 Clear