Score scripts can be attached to any cells or frames in the script. They appear in the pop-up Script menu at the top left of the score window (when the score is set to show the script menu, that is). Handlers contained within them are only accessible to ordinary events while the frames in which they appear are playing.
Movie scripts and the handlers they contain are globally accessible - they can be called from anywhere in the movie, by score script handlers, cast scripts, other movie scripts or events.
Both score and movie scripts are elements in the cast in their own right. You can choose whether a script is a score or movie script from the pop-up menu in the script info dialog box.
Cast scripts do not appear as separate cast members in themselves, but only as adjuncts to the bitmap, button or whatever they are attached to. They appear in the script window as "Script of cast member x". In general they respond only to events passed to the cast member they are attached to.
Messages normally pass through scripts in the order specified in the "Lingo Messaging Hierarchy" diagram on the back cover of the Lingo Dictionary, stopping as soon as they find a script with a handler that can use them. They can be made to continue down the hierarchy by using the pass command:
-- this is a sprite script on mouseUp -- do some sprite things first here mySpriteStuff -- then pass it on pass end mouseUp
This will send the mouseUp message along to the cast, frame and movie scripts once the sprite is done with it.
Although messages will only normally be passed in the order specified in the messaging hierarchy, it is possible to send messages directly to a specific script via lingo, even if that script would not normally receive such a message, using the script keyword:
message(script scriptName [, params...])
For example, suppose you wish to invoke the mouseUp handler in a castmember that isn't presently onstage. If the cast's name is "blah", then:
mouseUp(script "blah")
will do just that. This kind of thing should be done with care, however. In general, it's sensible to place your scripts in the appropriate places in the messaging hierarchy for the things you want them to do.
The rule of thumb is, place a handler in a script that's just far enough down the message-passing hierarchy to catch all the messages you want it to catch and none of those you don't. In practice, this usually means defining default catch-all responses in movie scripts, default button behaviours in cast scripts, and frame-specific actions in frame and sprite scripts.
Only a few cases are set in stone: startMovie & stopMovie handlers must be in movie scripts, because when they are executed there is no current frame. Parent scripts should usually be in score or cast scripts to hide their methods to calls that don't use their offspring. And all the generic handlers you want to be able to call from anywhere in your movie need to go in movie scripts.
global helpFrame on startMovie set helpFrame = 100 end startMovie
and you have a button in frame 20 that needs to use the value of helpFrame,
on mouseUp go to helpFrame end mouseUp
is not sufficient in the sprite script (you'll probably get a warning like "Variable used before assigned a value" when you compile the script). You need to add
global helpFrame
at the top of this script as well before it will work.
on mouseUp put the clickOn into me set newColor = (the foreColor of sprite me + 1) mod 256 set the foreColor of sprite me = newColor end mouseUp
The first thing the script does is determine which sprite it has been called for, and then it acts on that sprite.
Tracing should show up what script the handler occurs in. You can either modify that script to stop the default behaviour (either removing the handler altogether or changing the script type to "score"), or, if you want to retain the default behaviour in other cases, put a handler such as:
on exitFrame dontPassEventf17 end exitFramef17
in the script channel for that frame to intercept the exitFrame message.
message(script scriptName, any, required, parameters...)
For example, if you had a button called "help button" with a mouseUp handler in its cast script, you could cause its handler to be called by using:
mouseUp(script "help button")
(Note that you can also use cast numbers instead of names to specify the script, but in most cases it's safer to use names.)
While this is not strictly the same thing as sending an event to an object onstage (for instance, a button won't hilite on receiving this message), it nevertheless allows for most of the things you would want to do this way, since the actions of objects interacted with will usually be controlled by scripts.
Eg:
-- to switch between a series of actions depending on the value of -- our variable switchVar. This example assumes switchVar will have a -- numeric value, but you can use other values instead set actionsList = [ 0: "zeroAction", 1: "oneAction", 2: "twoAction",] do string(getAProp(actionsList, switchVar))
Note the outer "string" call. This is because, if switchVar contains a
value that isn't one of the list's properties, getAProp returns
An analogous structure can be used to do conditional assignments. Rather
than use a bunch of separate checks:
Combine them all into a single list assignment:
For more on the uses of lists, see section 12.
Director Web:
Director FAQ: [10] Lingo
HTML by Zac Belado, zac@wimsey.com
The Internet Connection at MCLI is
Alan Levine --}
URL: http://www.mcli.dist.maricopa.edu/director/faq/faq10.html
if x = 1 then set y = "one"
else if x = 2 then set y = "two"
else if x = 3 then set y = "three"
else if x = 4 then set y = "four"
set y = getAProp( [ 1: "one", 2: "two", 3: "three", 4: "four" ], x )
Maricopa County Community College District
Comments to
levine@maricopa.edu