User Guide
38 Chapter 2: Director Scripting Essentials
// JavaScript syntax
function jump(aVal) {
if(aVal == 5) {
return;
}
else {
aVal = aVal + 10;
return(aVal);
}
}
When you define a handler that returns a result, you must use parentheses after the handler when
you call it from another handler. For example, the statement
put(findColor()) calls the on
findColor
handler and then displays the result in the Message window.
Linear lists and property lists
In your scripts, you may want to track and update lists of data, such as a series of names or the
values assigned to a set of variables. Both Lingo and JavaScript syntax have access to linear lists
and property lists. In a linear list, each element in the list is a single value. In a property list, each
element in the list contains two values; the first value is a property name, and the second value is
the value associated with that property.
Because both Lingo and JavaScript syntax have access to linear and property lists, it is
recommended that you use linear lists and property lists if values in your code are shared between
Lingo and JavaScript syntax scripts.
If values in your code are used only in JavaScript syntax scripts, it is recommended that you use
JavaScript Array objects to work with lists of data. For more information on using arrays, see
“JavaScript syntax arrays” on page 45.
Creating linear lists
You create a linear list in one of the following ways:
• In Lingo, use either the top level list() function or the list operator ([ ]), using commas to
separate items in the list.
• In JavaScript syntax, use the top level list() function, using commas to separate items in
the list.
The index into a linear list always starts with 1.
When you use the top level
list() function, you specify the list’s elements as parameters of the
function. This function is useful when you use a keyboard that does not provide square brackets.
All of the following statements create a linear list of three names and assign it to a variable.
-- Lingo syntax
workerList = ["Bruno", "Heather", "Carlos"] -- using the Lingo list operator
workerList = list("Bruno", "Heather", "Carlos") -- using list()
// JavaScript syntax
var workerList = list("Bruno", "Heather", "Carlos"); // using list()