Expressions
Expressions are combinations of variables, values, and operators that are used in WinScript Live to perform logical analysis, trigger sequences, evaluate conditions in timed sequences, and perform mathematical operations. When used in WinScript Live, expressions are evaluated in their entirety as either true or false, unless they are used in mathematical operations, where they will return their calculated value.
Writing Expressions
Expressions use operators to compare values. An example using the Equal To operator (==) might look like:
"intMyInt == 10"
This expression will evaluate to true if the variable intMyInt equals 10, and false if it has any other value.
Tip
Prior to version 6.19.0 of WinScript Live, expressions had to be wrapped in quotation marks ("example"). As of version 6.19.0, expressions can either contain quotation marks (for backwards compatibility) or omit them. However, if you are using strings in your expression, you must not include quotation marks. See Using Values for more information.
The only case where an operator is not needed is when the expression comprises a single Boolean (binary) resource such as
input1
or
"bFireAlarm"
These expressions will evaluate to match the state of their respective resources. The first will be true if input1 is on and false if it is off. The second will be true if bFireAlarm is true and false if bFireAlarm is false.
Expressions can be very complex, using several values and variables along with functions and operators:
(bProjectorIsOn == true) && (intLampHours <= 1500) && (bFireAlarm != TRUE) && (strShowStatus == "Running")
Using Variables
An expression can comprise up to eight variables. Each variable is replaced with its current value before evaluating the expression.
Warning
Variable names that contain operators such as '-' must be wrapped in backtick marks.
Example
Given the variables and values listed below, choosing not to use backticks changes the meaning of the expression.
taco = 5
tuesday = 2
taco-tuesday = 7
"`taco-tuesday` + 1"
taco-tuesday (7), add 1 to it, and evaluate to 8.
Without backticks, the expression
"taco-tuesday + 1"
tuesday (2) from the value taco (5), add 1 to it, and evaluate to 4.
Using Values and Strings
Explicit values (literals) can also be used in expressions. For example, true or false can be used for Boolean comparisons:
bProjectorOn == true
Booleans, integers, decimals, percents, and timecode values are supported.
Strings are also supported for equality and inequality comparisons. Up to eight distinct string literals can be used in one expression.
Warning
Expressions that contain strings cannot be surrounded by quotes.
Example
myStr == "strValue"
"myStr == "strValue""
Expressions that do not contain strings may be surrounded by quotes. For instance, both
myVar == 0
"myVar == 0"
Note
Expressions that contain strings that contain quotation marks in the content of the strings must use an escape character (\) before each quotation mark in the string. For example,
(strSoundBite == "And he said: \"Plaaaay the best song in the world\"")
\).
When using timecode literals in an expression, the system frame rate is used by default. However, if the expression contains a timecode variable, then the timecode variable's frame rate will be used. Expressions support partial or full timecode values; as long as a colon is as a timecode delimiter, the expression will interpret it as a timecode value. Timecode values are evaluated as fractional seconds by default, unless the toframes function is used.
Operators and Functions
Table 2, Table 3 and Table 4 below list the Boolean Operators, Mathematical Operators, and Mathematical Functions that can be used in expressions.
| Operator | Description |
|---|---|
| ! | NOT |
| < | Less Than |
| <= | Less Than or Equal To |
| > | Greater Than |
| >= | Greater Than or Equal To |
| == | Equal To |
| != | NOT Equal To |
| && | AND |
| || | OR |
| Operator | Description |
|---|---|
| + | Add |
| - | Subtract |
| * | Multiply |
| / | Divide |
| % | Modulo |
| ^ | Power |
| () | Parentheses |
| `` | Backtick |
| Function | Description |
|---|---|
| cos(x) | cosine of a radian angle x |
| cosh(x) | hyperbolic cosine of x |
| acos(x) | arc cosine of x in radians |
| sin(x) | sine of a radian angle x |
| sinh(x) | hyperbolic sine of x |
| asin(x) | arc sine of x in radians |
| tan(x) | tangent of a radian angle x |
| tanh(x) | hyperbolic tangent of x |
| atan(x) | arc tangent of x in radians |
| atan2(y,x) | arc tangent in radians of y/x based on the signs of both values to determine the correct quadrant |
| abs(x) | absolute value of x |
| ceil(x) | rounds up x to a whole number |
| floor(x) | rounds down x to a whole number |
| ln(x) | natural log of x (base-e) |
| log(x) | log of x (base-10) |
| ncr(n,r) | number of unordered set of r items from a set of n items. (combinations) |
| npr(n,r) | number of ordered set of r items from a total of n items (permutations) |
| pow(x,y) | x to the y power |
| exp(y) | e to the y power |
| fac(x) | factorial of x |
| sqrt(x) | square root of x |
| pi() | Pi Constant - 3.14159... |
| e() | Euler's Number Constant - 2.71828... |
| toframes(x,y) | frame count of timecode x at y framerate |
| totime(x,y) | decimal value of timecode x at y framerate |
Using Expressions
Logic
Expressions can be used in logical analysis in conjunction with the If, Else If, Else, and End If events. When an expression for an If event is true, all events located after it and before an Else, Else If, or End If event will be executed. The events located after an Else If condition will be executed if all prior conditions were false and the Else If condition is true. The events located between the Else and End If events will be executed if all prior conditions were false.
An example using expressions in If and End If events is shown in Figure 1.

An example using expressions with If, Else If, Else, and End If events is shown below in Figure 2.

Conditions
Expressions can be used in the Condition field of an event in timed sequences. If an expression is associated with a timed event, that event will only execute if the expression evaluates to true. An example is shown below in Figure 3 (grid view) and Figure 4 (timeline view).
Note
Conditions in timed sequences will be evaluated one Pre-Roll period before the event should take effect, to allow time for events to be scheduled and messages to be sent.


Triggers
Expressions can also be used to trigger sequences, as shown in Figure 5. In this case, expressions are constantly evaluated and the trigger will occur if they ever become true.

Math
Mathematical operations are also possible thanks to expressions. Various operators and functions can be used to perform calculations using any constant or variable values you enter into the expression formula.
An example of incrementing a variable called intGuestCount is shown below in Figure 6.

An example calculating the length of a triangle's hypotenuse using the Pythagorean theorem is shown below in Figure 7.

Expression Test Dialog
Wherever expressions can be used, an option or button labeled Test or Expression Help will open the Test Expression dialog, as shown in Figure 8. This dialog allows you to enter an expression and see how the expression evaluates with different values for each resource in the expression.

If a resource name entered in the expression does not match an existing resource, or if the expression is invalid for any reason, an error will appear, as shown in Figure 9 and Figure 10.


If the expression contains correctly named resources, operators, and functions, the dialog will include fields below the expression where you can enter or select different values for each resource in the expression and see how the expression evaluates based on those values, as shown in Figure 11 and Figure 12.

