Using Director > Writing Scripts with Lingo > Controlling flow in scripts > Using case statements

 

Using case statements

The case statement is a shorthand alternative to repeating ifthen statements when setting up a multiple branching structure. A case statement is often more efficient and easier to read than a large number of if...then...else statements.

The condition to test for follows the term case in the first line of the case structure. The comparison goes through each line in order until Lingo encounters an expression that matches the test condition. When a matching expression is found, Director executes the Lingo that follows the matching expression.

For example, the following case statement tests which key the user pressed most recently and responds accordingly:

case (the key) of
	"A": go to frame "Apple"
	"B", "C":
		 puppetTransition 99
		 go to frame "Oranges"
	otherwise beep
end case

If the user pressed A, the movie goes to the frame labeled Apple.

If the user pressed B or C, the movie performs the specified transition and then goes to the frame labeled Oranges.

If the user pressed any other letter key, the computer beeps.

A case statement can use comparisons as the test condition.

For more information, see see if and case.