20
Chapter 2: Director Scripting Essentials
Constants
A constant is a named value whose content never changes.
In Lingo, the predefined terms
TRUE
,
FALSE
,
VOID
, and
EMPTY
are constants because their values
are always the same. The predefined terms
BACKSPACE
,
ENTER
,
QUOTE
,
RETURN
,
SPACE
, and
TAB
are constants that refer to keyboard characters. For example, to test whether the last key pressed
was the Space bar, use the following statement:
-- Lingo syntax
if _key.keyPressed() = SPACE then beep()
In JavaScript syntax, you can access predefined constants using some of the data types that are
unique to JavaScript syntax. For example, the Number object contains constants such as
Number.MAX_VALUE
and
Number.NaN
, the Math object contains constants such as
Math.PI
and
Math.E
, and so on.
Note:
This reference does not provide in-depth information about the predefined constants in
JavaScript syntax. For more information on these constants, see one of the many third-party
resources on the subject.
In JavaScript syntax, you can also define your own custom constants by using the
const
keyword.
For example, the following statement creates a constant named
items
, and assigns it a value of 20.
This value cannot be changed after it has been created.
// JavaScript syntax
const items = 20;
For more information on constants, see
Chapter 9, “Constants,” on page 151
.
Symbols
A symbol is a string or other value in Lingo that begins with the pound (
#
) sign.
Symbols are user-defined constants. Comparisons using symbols can usually be performed very
quickly, providing more efficient code.
For example, the first statement below runs more quickly than the second statement:
-- Lingo syntax
userLevel = #novice
userLevel = "novice"
Symbols cannot contain spaces or punctuation.
In both Lingo and JavaScript syntax, convert a string to a symbol by using the
symbol()
method.
-- Lingo syntax
x = symbol("novice") -- results in #novice
// JavaScript syntax
var x = symbol("novice"); // results in #novice
Convert a symbol back to a string by using the
string()
function (Lingo) or the
toString()
method (JavaScript syntax).
-- Lingo syntax
x = string(#novice) -- results in "novice"
// JavaScript syntax
var x = symbol("novice").toString(); // results in "novice"
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...