Conditional constructs

By default, Director always executes script statements starting with the first statement and continuing in order until it reaches the final statement or a statement that instructs a script to go somewhere else.

The order in which statements are executed affects the order in which you should place statements. For example, if you write a statement that requires some calculated value, you need to put the statement that calculates the value first.

The first statement in the following example adds two numbers, and the second statement assigns a string representation of the sum to a field cast member named Answer, which appears on the Stage. The second statement could not be placed before the first statement because the variable x has not yet been defined.

-- Lingo syntax 
x = 2 + 2 
member("Answer").text = string(x) 
// JavaScript syntax 
var x = 2 + 2; 
member("Answer").text = x.toString();

Both Lingo and JavaScript syntax provide conventions for altering the default execution order or script statements, and for performing actions depending on specific conditions. For example, you may want to do the following in your scripts:

  • Execute a set of statements if a logical condition is true, or execute alternate statements if the logical condition is false.

  • Evaluate an expression and attempt to match the expression’s value to a specific condition.

  • Execute a set of statements repeatedly until a specific condition is met.