User Guide
Writing Scripts with Lingo 403
Variables can also hold the results of mathematical operations. Both of these statements add the
result of an addition operation to the variable
mySum:
mySum = 5 + 5
set mySum = 5 + 5
It’s good practice to use variable names that indicate what the variable is used for. This will make
your Lingo easier to read. For example, the variable mySum indicates that the variable contains the
sum of numbers.
To test the values of properties or variables:
• Use the put command in the Message window or check the values in the Watcher window.
For example, the statement
put myNumber displays the value assigned to the variable myNumber in
the Message window.
As another example, the following statement returns the cast member assigned to sprite 2 by
retrieving the sprite’s
member property:
put the member of sprite 2
Using global variables
Global variables can be shared among handlers and movies. A global variable exists and retains its
value as long as Director is running or until you issue the
clearGlobals command.
In Macromedia Shockwave, global variables persist among movies displayed by the Lingo
goToNetMovie command, but not among those displayed by the goToNetPage command.
Every handler that declares a variable as global can use the variable’s current value. If the handler
changes the variable’s value, the new value is available to every other handler that treats the
variable as global.
It’s good practice to start the names of all global variables with a lowercase g. This helps identify
which variables are global when you examine Lingo code.
Because you usually want global variables to be available throughout a movie, it is good practice
to declare global variables in an
on prepareMovie handler. This ensures that the global variables
are available from the very start of the movie.
To declare that a variable is global, do one of the following:
• Use the term global before the variable name at the top of the Script window, before any
individual handlers. This makes the variable global for every handler in the script.
• Declare the variable as global by using the term global before the variable name on a separate
line in every handler that uses the global variable.
When you use the term
global to define global variables, the variables automatically have VOID
as their initial value.
The following statements make
gName a global variable and give it the value Mary:
global gName
gName = "Mary"
To display all current global variables and their current values:
• Use the showGlobals command in the Message window.