Using Director > Writing Scripts with Lingo > About variables > Using global variables |
![]() ![]() ![]() |
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 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 |
![]() |
Declare the variable as global by using the term |
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.
To clear all current global variables:
Use the clearGlobals
command in the Message window to set the value of all global variables to VOID
.
See clearGlobals and showGlobals
.
![]() ![]() ![]() |