User Guide
Writing Scripts with Lingo 423
To remove an object from actorList:
• Use the delete command to delete the item from the list. See delete in the Lingo Dictionary.
Using scriptInstanceList
You can use the
scriptInstanceList property to dynamically add new behaviors to a sprite.
Normally, scriptInstanceList is the list of behavior instances created from the behavior
initializers defined in the Score. If you add child objects created from parent scripts to this list, the
child objects receive the messages sent to other behaviors.
For example, this statement adds a child object to the
scriptInstanceList property of sprite 10:
add sprite(10).scriptInstanceList, new(script "rotation", 10)
This is a possible parent script that the statement refers to:
-- parent script "rotation"
property spriteNum
on new me, aSpriteNum
spriteNum = aSpriteNum
return me
end
on prepareFrame me
sprite(spriteNum).rotation = sprite(spriteNum).rotation + 1
end
When a child object is added to scriptInstanceList, you must initialize the child object’s
spriteNum property. Typically you do this from a parameter passed in to the on new handler.
Note: The beginSprite message is not sent to dynamically added child objects.
Using actorList
Lingo can set up a special list of child objects (or any other objects) that receives its own message
each time the playhead enters a frame or the
updateStage command updates the Stage.
The special list is
actorList, which contains only objects that have been explicitly added to the
list. See actorList in the Lingo Dictionary.
The message is the
stepFrame message that is sent only when the playhead enters a frame or the
updateStage command is used. See on stepFrame in the Lingo Dictionary.
Objects in
actorList receive a stepFrame message instead of an enterFrame message at each
frame. If the objects have an
on stepFrame handler available, the Lingo in the on stepFrame
handler runs each time the playhead enters a new frame or the
updateStage command
updates the Stage.
Some possible uses of
actorList and stepFrame are to animate child objects that are used as
sprites or to update a counter that tracks the number of times the playhead enters a frame.
An
on enterFrame handler could achieve the same results, but the actorList property and on
stepFrame
handler are optimized for performance in Director. Objects in actorList respond
more efficiently to
stepFrame messages than to enterFrame messages or custom messages sent
after an
updateStage command.
To add an object to the actorList:
• Use the statement add the actorList, theObject.