Logic

“Logic is the beginning of wisdom, not the end of it.”

That said, there’s no substitute for logic in programming, and it’s what separates the greater and the lesser mortals (apologies for the logic joke).

Logic Events

Most of our logic statements start with the word IF, which makes sense. We want to do an action only IF some condition is met. IF the number of guests in the theater is > 50, start the show. IF the time is > sunrise, turn on the show equipment for the day. IF the system is Off mode, and we receive a start request, ignore it or report an error to the users. Here are the IF statements that are available

If <
If <= If = If >
If >=
If Not =
If Off
If On

Using each of these events works essentially the same, just comparing one value against another. Each has two variations – the “End If” variation and the Goto Label Variation. In the “End If” variation, you can run as many statements as you want inside the conditional logic, and they’ll only be executed if the condition is true. After your final event, you add another event called “End If” which ends the set of conditional statements.

If 4 > 3
Event1
Event2
End If

The Goto Label variation executes on a single line and doesn’t execute any other statements. If the condition evaluates to true, it will jump from the event it’s into the event with the Label matching the event statement’s 3rd parameter.

The Goto version is often used to bail out of running out a sequence when the system is in the wrong mode or state to do a particular action. It’s very efficient and multiple IF statements can jump to the same label, so you can check for Power Status, System Mode, and other conditions and jump to an “Exit” label before running any show events.

Related to the If statement is the “Else” statement. This logic will execute if the conditional statement evaluates to False.

If 3 > 4
Event 1
Event 2
Else
Event 3
Event 4
End If

In this example only Event 3 and Event 4 will be executed.

Two statements that aren’t commonly used but are part of logic are the bitwise operators,
BitAnd and BitOr. These take an Integer or Timecode value and perform binary math on them, returning a value that represents either the value where both variables are 1 (BitAnd) or the value where either of the values are 1. It’s a little hard to see without visualizing it, so let’s take a look.

BitAnd – “For example, a Variable with a value of 3 (0011) and a constant with a value of 1 (0001) would give a result of 1 (0001).”
BitOr – “For example, a Variable with a value of 8 (1000) and a constant with a value of 1 (0001) would give a result of 9 (1001).”

Bitwise operations are frequently operationally faster than doing Math functions because they don’t require calculating a response, only checking to see if a particular value matches in a binary position.

Goto
If you are doing other math and need to jump to another label (say an Exit label like the previous example), the goto statement does that jump for you. This gives you the ability to combine the power of the two types of IF statements into one where you need it.

Closely related to these conditional functions are mathematical expressions that work on variables and set the stage for use in conditional statements.

Add
Divide
Floor
Mod
Multiply
Round
Subtract

EVAL (take Adam’s examples)
The Eval is a powerful new function that allows you to use multiple mathematical expressions inside a single event and return the result into a variable. As a simple example, we can do a square root, or absolute values or factorials – all the currently available functions are in the Show Control User’s Guide, but here’s a quick example

Eval ResultVariable “sqrt(9)”

This would set the ResultVariable to 3.

Logic is an incredibly powerful part of the show control toolkit, particularly when it comes to making decisions based on the state of variables and system conditions. You’ll get a chance to stretch your logic muscles in the labs, so give those a try and if you run into questions, just reach out!