These kind of tasks are much more powerful than Cuelists. Scripts offer access to the integrated Basic language. The modern compiler compiles native code for every supported platform. V-Control Basic enhances the standard Basic by commands giving access to the Device Driver and Tasks as well as to globally shared variables. In the Compiler section, there is a list of all available commands and functions.
To create a Script switch to Script View.
Then select Tasks → Add in main menu or via Cueset list context menu (right click) select Add Task. Alternatively the click the Add Task tool button.
Now the task has to be filled with instructions. Generally this is the same procedure than programming Cuelists. In the following example we send an OSC (Open Sound Control) message to a device. Select the device in the Device List, select the command in the Command List and enter the parameter. Then click the Add Cmd button.
The command generated has this structure:
RunCmd("Device Name","Channel Name","Command Name","Device Parameter 1","Device Parameter 2", "Command Parameter 1","Command Parameter 2","Command Parameter 3","Command Parameter 4")
Parameters that are empty shown as “”
So the resulting entry is
Next step is to modify this command. Assume that the SimpleOSCInteger command controls a fader value, and the fader should move from 0 to 100 in 2 seconds. The script can be something like this:
Dim v as Variant creates a local variable v. The type Variant is very flexible. It behaves as an integer if used so. But the content of the variable is converted to string if a string is needed. The For loop accepts only Integers as loop iterator, but the RunCmd Function accepts only string parameters. In both cases we can use a variant variable.
Here is an example with Integer and String Variables:
Dim i as Integer Dim s as String for i = 0 to 100 s = str(i) RunCmd("OSC_1220","osc","SimpleOSCInteger","/test","",s,"","","") Delay("20") Next
The str Function converts an Integer to String
Every RunCmd instruction changes the variable IOResult. IOResult does not have to be declared, it is a (string) variable that is part of every Script and contains the result of the last RunCmd instruction.
In the example above a
Get_ADC_1 command is sent to a C-Control I/O interface. The result of the command is stored in the variable IOResult. The value of IOResult is (in this case) the measured value of analog digital converter (ADC) 1 of the C-Control interface. Because the type of IOResult is string, but the value is needed (for comparison) as integer, the line
i = Val(IOResult) converts the string to an integer. If the measured value is bigger than 25, an air condition is switched on.
It might be necessary to have a Delay between two commands to pause the task for a given amount of time. In the main menu select Insert → Delay or use the context menu. The Delay is specified by the value in milliseconds.
Even in complex projects it makes sense to split the whole project into several subroutines. This makes maintenance easier and gives a better overview over the projects structure. Every Task, whether a Cuelist or Script, can be a function. If a task is executed, it is usually processed from top to bottom. A CallAsFunction branches to the task specified, finishes the called task and returns to the next command in the calling task.
To call a task as function, select Insert → CallAsFunction in main menu or Script Editor context menu (right click Insert → CallAsFunction). That opens the Task Selector presenting all tasks (Cuelists and Scripts). Choose the task that has to be called.
In contrast to CallAsFunction, a CallAsThread instruction launches the new task parallel to the calling task. The calling task is not paused during the time, the called task is executed. The programmer / operator has to take care that the two parallel running tasks don't use the same resources (devices / channels).
To create a CallAsThread instruction select Insert → CallAsThread in main menu or use the Script Editor's context menu (right click Insert → CallAsThread). That opens the Task Selector presenting all tasks (Cuelists and Scripts). Choose the task that has to be called.
It might be necessary to stop a running task before it terminates regularly. This can be done manually via Icon / Toolbar) or as instruction from a running task. Assuming there is an endless loop working with two DVD Players. Now the DVD Player are needed for some other action, but it is impossible to use them as long as the endless loop is running, because they are blocked. With the StopTask command it is possible to terminate the endless loop and then use the DVD Players in another task.
The command is available via main menu Insert → Stop Task or the Script Editor's context menu. That opens the Task Selector presenting all tasks (Cuelists and Scripts). Choose the task that has to be stoped.
The ShowMessage command is used to display a message in the status bar. Via main menu Insert → Show Message or Script Editor's context menu this command is available.
Local variables are only available in the task where they have been declared. While declaring a variable, its type is set. The following types are available:
It is possible to build arrays from all those types.
A variable is declared by the Dim statement. Variable names must start with a letter and must not contain special characters. Here some examples:
Dim A1 As Integercorrect
Dim Ä1 As Integerincorrect
Dim 1A As Integerincorrect
Dim A 1 As Integerincorrect, space not allowed
Dim A_1 As Integercorrect
In the screenshot above, the Dim statement declares a String variable named foo. Then, the variable foo gets the value “Hallo Welt”. The content of foo is displayed by the ShowMessage command with foo as parameter. In this example, a line ShowMessage(“Hallo Welt”) would have the same result.
Variant variables are very special. Because they have no (or any) type, they are very flexible. A variant stores a value in different formats and “knows” which one is needed if there is an access to. In the example below a variant variable named v is declared:
For..Next loop, an integer value is assigned to v. As discussed above, the ShowMessage command need a string variable as parameter, but the line ShowMessage(“Count:” + v) is working correct, because v knows that only strings are valid and present its content as string. So v is used as integer and as string in the same subroutine. A more structured solution for the same job is the example below:
At first, an integer variable i is declared. The beginning of the
For..Next loop is unchanged, because the For..Next instruction expect an integer variable anyway. The command
ShowMessage(“Count:”+ i) will not work, because it is impossible to add an integer to a string. But V-Control Basic knows a function that converts an integer to string, the
Str(i) command. The result of str(i) is “10”, if i has the value 10. The string “10” comprising from ASCII code 49 (“1”) and ASCII code 48 (“0”).
An Overview of available basic functions is available in the Basic Language Reference Chapter.
Another often used variable type is boolean. Boolean variables know to states, True or False (1/0).
In this example, the variable b1 is declared as Boolean. The PromptMessage command need a boolean variable to return the result of the PromptMessage dialog. If the result is True, the OK button was pressed, if False, the user clicked the Cancel button. The if..then instruction check b1 and branch to the correct ShowMessage command.
Global variables are accessible from every Script. It is possible e.g. to assign a global variable a value in task A, and check this value in task B. Global variables are from type string only. Because every Script has access to global variables, it is not declared in a Script. To declare a global variable, select Cues → Add Global Variable… in the main menu or use the context menu of the Global Variables list.
Enter the name of the variable in the dialog box:
The new variable appears in the Global Variables list. At this point, the content of the new variable is an empty string “”.
To access the global variables, the commands GetGlobalVar and SetGlobalVar are used (available via main menu Insert → GetGlobalVar, Insert → SetGlobalVar or the Script Editor's context menu).
To assign a value to a global var, use the function SetGlobalVar. As shown in the picture above, it is available via Script Editor's context menu. In the following dialog (see below) select a variable from the list and enter a value for that variable:
The result is
If this task is launched, the variable MyVariable gets the string “Hello” as content. To check this, run the task.
To read a global variable use GetGlobalVar. Instructions like “MyVariable” = “6” are invalid, because “MyVariable” is a string and not a variable. MyVariable = “6” is also invalid, because MyVariable is not declared in the Script and only (locally) declared variables are known. The solution is to declare a local variable of type string and assign the content of the global variable to that local one.
Dim MyLocalVar as string
Via main menu Insert → GetGlobalVar, or the Script Editor's context menu a dialogue box with all available global variables pops up. If a variable is selected a new dialogue box asks for the local variable, that gets the content of the global one.
The result looks like this:
now, the content of the global variable is available in the Script and we can work with it.