CueServer 2 has the ability to trigger actions on time-based events called timers. Timers can trigger actions such as Cues, Macros, Presets or any other CueScript command(s).
In this tip and trick, the goal is to integrate toggle functionality with these timers. This article will demonstrate three ways of using logic with CueScript to accomplish that goal.
CueServer operates lighting in a building and incorporates an array of timers to ensure the lighting activity corresponds to building hours. On occasion, events are held at the building after hours. When the timers are triggered, the lighting will become inactive. To prevent this from happening, a toggle will be implemented to prevent the timers from taking normal action when needed.
In order to accomplish this task, logic must be applied. Logic can be applied in CueScript through the use of IF/Then and Break statements in conjunction with local or system variables.
In this example, logic dictates that there must be a way to track the status of the toggle. Either a local or system variable can be used for this.
Once the the toggle state is trackable, the only logic remaining is to determine the toggle state before an action is executed and prevent execution if the state is not true.
In the first method a variable, timersEnabled, will be used to track the state of the toggle. A button will be used as the toggle-trigger.
A rule must be added to the button (using the is Pressed condition and Perform Script modifier) to set the toggle to a boolean value of either 0 or 1. The code to accomplish this is:
"timersEnabled" = ('timersEnabled' == 0)
This will set the variable timersEnabled to the result of the statement
'timersEnabled' == 0.
If timersEnabled is undefined or equal to 0, that statement is true. Otherwise, if timersEnabled is set to any value other than 0, that statement is false.
With the button rule in place, the variable can be used in conjunction with If/Then logic to test the toggle's state.
The code below will be added as a rule to the timer:
If ('timersEnabled') Then
playback 1 clear
The logic above will check the toggle (timersEnabled) for its state. If the toggle's state is false, the action (playback 1 clear) will not be executed. Alternatively, if the toggle’s state is true, the nested action will be executed.
The button rule above will allow for the state to toggle whenever the button is pressed. The state of the toggle is directly tied to the execution of the timer's action by the code above. As a result, when the button is pressed, the timer’s execution is toggled between active and inactive.
Using this method does not prevent the timer from triggering, rather it prevents the action within the timer from being executed when the toggle is set to false.
The second method will also utilize a variable, breakTimers, to maintain a value. This method also uses logic to determine the state of the variable. A button will be used to toggle the state of the variable as it was in the first method.
The code needed for the button rule is:
If ('breakTimers' = "break") Then
"breakTimers" = ""
If ('breakTimers' != "break") Then
"breakTimers" = "break"
This code checks the value of the variable breakTimers against the value “break”. If the variable is equal to anything other than “break”, the value is set to “break”. If the value is already equal to "break", the value is set to an empty string.
The button rule is in place and now the variable can be placed into the timer’s rule.
The code below will be adde the the timer rule:
`breakTimers` playback 1 clear
Make note of the back-ticks used to call the variable breakTimers. This is important as CueScript executes the three variations of quotation marks differently.
- Single quotations (') are used to insert the value in place of the called variable.
- Double quotations (") are used to either set a variable or contain a string.
- Back-tick quotations (`) are used to insert the value in place of the called variable and then execute that value as a CueScript command.
In this case, breakTimers is called using the back-ticks variation, therefore, the value of breakTimers is placed into the rule as a command.
If the breakTimers value is an empty string, no command is placed into the rule and the variable is ignored.
If the breakTimers value is “break”, the command break is inserted in place of the variable and executed. Because the variable is placed before the timer’s actions, any and all commands following the variable (replaced by "break") are prevented from execution.
The third and final method will not use a variable. This method will make use of an indicator as a system variable of sorts.
Once again, a button will be used to toggle the state of the timer. The code added to the button rule will be:
indicator 1 toggle on
This code uses the toggle command to toggle the indicator status between off and on, or more precisely, 0 and 255.
Just as with the first two methods, the toggle has been created and attached to the button and now the logic using that toggle must be added to the timer.
The logic used for the timer will be:
If (indicator 1) Then
playback 1 clear
Make note of the lack of quotations around the toggle (indicator). Because indicator is a system variable of sorts, or rather a selection command, no quotes are needed for it’s use. Furthermore, by wrapping the indicator in parentheses, the contents inside are treated as an evaluation statement. The return of this evaluation is then used in the logic of the If/Then statement.
Given the indicator value toggling between 0 and 255, the indicator is thus evaluated to a boolean result of either 0 or 1 (true or false). The If/Then state evaluates the Indicator state and, if on, evaluates to true and executes the timer actions.
Have an Idea?