User Guide

Variables 23
To display all current global variables and their current values:
Use the Global objects showGlobals() method in the Message window.
For more information on the Message window, see “Debugging in the Message window”
on page 87.
To clear all current global variables:
Use the Global object’s clearGlobals() method in the Message window to set the value of all
global variables to
VOID (Lingo) or undefined (JavaScript syntax).
To monitor the values of global variables during movie playback, use the Object inspector. For
more information on the Object inspector, see “Debugging in the Object inspector” on page 91.
Global variables in Lingo
In Lingo, variables are considered local by default, and you do not need to precede the variable
name with any keyword. To declare a global variable, you must precede the variable with the
keyword
global.
If you declare a global variable at the top of a script and before any handlers, the variable is
available to all handlers in that specific script. If you declare a global variable within a handler, the
variable is available only to that handler; however, if you declare a global variable with the same
name within two separate handlers, an update to the variable’s value in one handler will also be
reflected in the variable in the other handler.
The following example illustrates working with two global variables:
gScript, which is available
to all handlers in the script, and
gHandler, which is available within its defining handler and any
other handlers that declare it on the first line of the handler.
-- Lingo syntax
global gScript -- gScript is available to all handlers
on mouseDown
global gHandler
gScript = 25
gHandler = 30
end
on mouseUp
global gHandler
trace(gHandler) -- displays 30
end
In Lingo, when you use the term global to define global variables, the variables automatically
have
VOID as their initial value.
Global variables in JavaScript syntax
In JavaScript syntax, variables are considered global by default. The scope of a global variable can
be determined by how and where it is declared.
If you declare a variable within a JavaScript syntax function without preceding the variable
name with the keyword
var, the variable is available to all functions within its containing
script.
If you declare a variable outside a JavaScript syntax function, with or without the keyword var,
the variable is available to all functions within its containing script.