User Guide

Object-oriented programming with Lingo 57
A parent script makes another parent script its ancestor by assigning the script to its ancestor
property. For example, the following statement makes the script What_Everyone_Does an
ancestor to the parent script in which the statement occurs:
-- Lingo syntax
ancestor = new(script "What_Everyone_Does")
When handlers and properties are not defined in a child object, Director searches for the handler
or property in the childs ancestors, starting with the child’s parent script. If a handler is called or
a property is tested and the parent script contains no definition for it, Director searches for a
definition in the ancestor script. If a definition exists in the ancestor script, that definition is used.
A child object can have only one ancestor at a time, but that ancestor script can have its own
ancestor, which can also have an ancestor, and so on. This lets you create a series of parent scripts
whose handlers are available to a child object.
Writing a parent script
A parent script contains the code needed to create child objects and define their possible actions
and properties. First, you must decide how you want the child objects to behave. Then, you can
write a parent script that does the following:
Optionally declares any appropriate property variables; these variables represent properties for
which each child object can contain a value independent of other child objects.
Sets up the initial values of the child objects’ properties and variables in the on new handler.
Contains additional handlers that control the child objects’ actions.
Declaring property variables
Each child object created from the same parent script initially contains the same values for its
property variables. A property variable’s value belongs only to the child object it’s associated with.
Each property variable and its value persists as long as the child object exists. The initial value for
the property variable is typically set in the
on new handler; if its not set, the initial value is VOID.
To declare a property variable:
Use the property keyword at the beginning of the parent script.
To set and test property variables from outside the child object:
Set and test property variables in the same way you would any other property in your scripts,
by using the syntax
objectRef.propertyName.
For example, the following statement sets the
speed property of an object car1:
car1.speed = 55
Creating the new handler
Each parent script typically uses an
on new handler. This handler creates the new child object
when another script issues a
new(script parentScriptName) command, which tells the
specified parent script to create a child object from itself. The
on new handler in the parent script
can also set the child objects initial property values, if you want.
The
on new handler always starts with the phrase on new, followed by the me variable and any
parameters being passed to the new child object.