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.
Summary of Contents for DIRECTOR MX-USING DIRECTOR MX
Page 1: ...Using Director MX Macromedia Director MX...
Page 12: ...Contents 12...
Page 156: ...Chapter 4 156...
Page 202: ...Chapter 6 202...
Page 244: ...Chapter 7 244...
Page 292: ...Chapter 10 292...
Page 330: ...Chapter 12 330...
Page 356: ...Chapter 13 356...
Page 372: ...Chapter 14 372...
Page 442: ...Chapter 16 442...
Page 472: ...Chapter 18 472...
Page 520: ...Chapter 19 520...
Page 536: ...Chapter 20 536...
Page 562: ...Chapter 23 562...
Page 566: ...Chapter 24 566...
Page 602: ...Chapter 27 602...