Overview

Functions are user-definable code blocks that can be executed to accomplish a task, similar to macros. Unlike macros, Functions can have parameters, return values, and be written in JavaScript as well as CueScript. Functions can be called directly from CueScript, optionally with arguments, and can interact with JavaScript Plugins or Event Handlers.

The Function editor is where you add, modify, or adjust user-defined CueScript or JavaScript functions.


Add a Function

Click the plus button ( ) to add a new function. A new row will appear with the Name field focused.

Enter the name that will be used to invoke the function.

If the function will accept arguments, use the tab key to move the focus to the Parameters field.

Enter the name of each parameter, separated by commas.

Enter the script that the function will execute in the script box at the bottom.

Click Apply to save the function.


Remove a Function

To remove a function, select the function in the list, and then select the minus button ( ), or use the delete/backspace key.

A popup will appear asking if you want to delete the function. Click Delete.


Function Types

CueServer functions can be written using CueScript or JavaScript syntax.

Use the type menu ( ) to define which syntax a function uses.

CueScript function

CueScript functions are similar to macros, but can utilize parameters and return values. CueScript functions have access to all of the normal CueScript syntax, can access user variables, and can query, capture, and use the results of CueScript commands.

Arguments are accessible in the scope of the function and can be accessed in the same way as a global or system variable. If a parameter is used with the same name as a global variable, the provided argument value will take precedence within the scope of the function. For information on how to use CueScript variables, see the variables section.

CueScript functions can return a value with the Return command.

Javascript function

CueServer’s embedded JavaScript engine supports ECMAScript E5 syntax. In addition to the most of the standard JavaScript API’s, functions also have access to a host of CueServer-specific JavaScript API’s.

To access the library of functions and their documentation, use the Insert Function Call button ( ) to open the functions panel. Choosing a function and then clicking the Add button will insert a template of that function into the script.

Arguments are accessible as normal variables in the local scope of the function.

A value can be returned with the JavaScript reserved word return.


Using Functions

To call a CueScript or JavaScript function, wrap the call in square brackets ([]), with the arguments in parentheses:

[ add(2, 3) ]

If a value is returned, it can be stored in a variable or used inline with commands:

"x" = [ add(2, 3) ]
Sets the variable x to the number 5.

"x" = ([ add(2, 3) ] + 5)
Sets the variable x to the number 10.

cue [ add(2, 3) ] go
Sets Cue 5 as the next Cue and executes it.