28
Chapter 2: Director Scripting Essentials
The
not
(Lingo) or ! (JavaScript syntax) operator is useful for toggling a
TRUE
or
FALSE
value to
its opposite. For example, the following statement turns on the sound if it’s currently off and
turns off the sound if it’s currently on:
-- Lingo syntax
_sound.soundEnabled = not (_sound.soundEnabled)
// JavaScript syntax
_sound.soundEnabled = !(_sound.soundEnabled);
String operators
String operators combine and define strings.
Use care when using logical operators and string operators in Lingo and JavaScript syntax. For
example, in JavaScript syntax
&&
is a logical operator that determines whether two expressions are
true, but in Lingo,
&&
is a string operator that concatenates two strings and inserts a space
between the two expressions.
Conditional constructs
By default, Director always executes script statements starting with the first statement and
continuing in order until it reaches the final statement or a statement that instructs a script to go
somewhere else.
The order in which statements are executed affects the order in which you should place
statements. For example, if you write a statement that requires some calculated value, you need to
put the statement that calculates the value first.
The first statement in the following example adds two numbers, and the second statement assigns
a string representation of the sum to a field cast member named
Answer
, which appears on the
Stage. The second statement could not be placed before the first statement because the variable
x
has not yet been defined.
-- Lingo syntax
x = 2 + 2
member("Answer").text = string(x)
// JavaScript syntax
var x = 2 + 2;
member("Answer").text = x.toString();
Operator
Effect
Precedence
&
(Lingo only) Concatenates two strings
2
+
(JavaScript syntax only) Concatenates two string values and returns a
third string that is the union of the two operands
2
+=
(JavaScript syntax only) Concatenates one string variable and one
string value, and assigns the returned value to the string variable
2
&&
(Lingo only) Concatenates two strings and inserts a space between
the two
2
"
Marks the beginning or end of a string.
1
Summary of Contents for DIRECTOR MX 2004
Page 1: ...DIRECTOR MX 2004 Director Scripting Reference...
Page 48: ...48 Chapter 2 Director Scripting Essentials...
Page 100: ...100 Chapter 4 Debugging Scripts in Director...
Page 118: ...118 Chapter 5 Director Core Objects...
Page 594: ...594 Chapter 12 Methods...
Page 684: ...684 Chapter 14 Properties See also DVD...
Page 702: ...702 Chapter 14 Properties See also face vertices vertices flat...
Page 856: ...856 Chapter 14 Properties JavaScript syntax sprite 15 member member 3 4...
Page 1102: ...1102 Chapter 14 Properties...