Variables

Director uses variables to store and update values. As the name implies, a variable contains a value that can be changed or updated as a movie plays. By changing the value of a variable as the movie plays, Director can do things such as store a URL, track the number of times a user takes part in an online chat session, record whether a network operation is complete, and many more options.

It is a good idea always to assign a variable a known value the first time you declare the variable. This is known as initializing a variable. Initializing variables makes it easier to track and compare the variable’s value as the movie plays.

Variables can be global or local. A local variable exists only as long as the handler in which it is defined is running. A global variable can exist and retain its value as long as Director is running, including when a movie branches to another movie. A variable can be global within an individual handler, a specific script, or an entire movie; the scope depends on how the global variable is initialized.

If you want a variable to be available throughout a movie, it is good practice to declare it in an on prepareMovie (Lingo) or a function prepareMovie() (JavaScript syntax) handler. This ensures that the variable is available from the very start of the movie.

For more information on using both global and local variables, see Using global variables and Using local variables.