Lingo Programming

If you want your movie to do anything other than just play from beginning to end, you must control what it does with Lingo.

Lingo is ...

Lingo commands are terminated by a RETURN character. If your line is getting too long, you can place the "\" continutation character at the end of the line, and continue on the next line.

Comments are preceded by "--", and end with the end of the line.

Events

A Lingo "program" is actually a collection of functions or handlers. A handler defines what should be done when it is invoked in response to either an event or a direct call. All Lingo commands must appear inside a handler, and are executed only when that handler is invoked.

Director automatically detects a number of events when the movie is playing. Here are just a few:

Scripts

A script is a collection of one or more handlers, which can be viewed on the same page. Director supports 4 types of scripts:

Whenever an event occurs, Director uses the following hierarchy to determine what handler (if any) should be invoked:

You may also intercept this hierarchy by defining a primary event handler:

Example:

set the keyDownScript to "detectKeys"

After the specified handler is executed, it passes the event on to the usual event hierarchy unless it encounters a dontPassEvent instruction.

Defining Handlers

Handlers are subroutines (procedures or functions) that accomplish specific tasks. All handler definitions begin with the keyword on and end with the keyword end.

Handlers are defined using the syntax:

on handlername [ param1, param2, ... ]
    statements
end [ handlername ]

In addition to performing tasks, a handler may return a value

return expression

Handlers are called one of two ways

Variables

Variables are named memory slots that contain information that may change as the program is executed

Variable Types

Variable type is determined by its contents. A variable that has not been assigned a value has a default value of <Void>.

Variable Assignment and Operators

Variable values are set one of two ways:

set varname to expression

set varname = expression

Lists

Lists are ordered sets of values, like arrays or records (struct) in other programming languages.

Linear Lists

Linear lists contain sequences of values, referred to by their positions.

Property Lists

Property lists contain labeled values, referred to by their labels. You may also use numbers instead of labels.

Objects

An object is an entity with properties and behaviors defined by a class.