User Guide

204 Chapter 11: Keywords
Description
Keyword; starts a multiple branching logic structure that is easier to write than repeated
if...then statements.
Lingo compares the value in
case expression to the expressions in the lines beneath it, starting
at the beginning and continuing through each line in order, until Lingo encounters an expression
that matches
case expression.
When Lingo finds a matching expression, it executes the corresponding statement or statements
that follow the colon after the matching expression. When only one statement follows the
matching expression, the matching expression and its corresponding statement may appear on
the same line. Multiple statements must appear on indented lines immediately below the
matching expression.
When more than one possible match could cause Lingo to execute the same statements, the
expressions must be separated by commas. (The syntax line containing
expression3 and
expresssion4 is an example of such a situation.)
After Lingo encounters the first match, it stops testing for additional matches.
If the optional
otherwise statement is included at the end of the case structure, the statements
following
otherwise are executed if there are no matches.
Example
The following handler tests which key the user pressed most recently and responds accordingly.
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 key, the computer beeps.
on keyDown
case (_key.key) of
"a": _movie.go("Apple")
"b", "c":
_movie.puppetTransition(99)
_movie.go("Oranges")
otherwise: _sound.beep()
end case
end keyDown
This case statement tests whether the cursor is over sprite 1, 2, or 3 and runs the corresponding
Lingo if it is:
case _movie.rollOver() of
1: sound(1).play(member("Horn"))
2: sound(1).play(member("Drum"))
3: sound(1).play(member("Bongos"))
end case