There are 4 basic kinds of scripts: frame scripts, sprite/button scripts, movie scripts, and castmember scripts. All scripts, complete or incomplete, are listed in the script box of the upper-left of the score window. Before a movie is finished, any incomplete or unused scripts should be deleted.
All scripts are cast members. They can be created in script windows by defining 'variables', or by using 'handlers' (eg. "on exitFrame", "on mouseUp", "on startMovie") to initiate an 'event' which is determined and defined by following lingo statements.
The interior elements of scripts between the handler ("on exitFrame", etc.) and the "end", are indented to indicate their correct structure and function. To check proper indentation, use the Tab key. Scripts which do not indent properly are probably not written correctly and may not function as intended. Scripts must be completed with the unindented term "end", and finally authorized/entered by hitting 'return' (or enter) and/or closing the script window.
They can be changed or added to, like any text-editing function, as long as the indentation and protocol for "end" is correct. Each script can contain numerous lingo statements which define several separate events, or define and extend the same event.
In the beginning, scripts and their lingo statements should be kept as simple and clear as possible to avoid confusion and bugs. Scripts can be viewed as the movie plays by opening the Message window (comm-m) and checking the Trace box. Bugs can then be corrected directly from the Message window. Tracing the scripts as the movie plays also recompiles all the scripts so that they execute more smoothly.
Many bugs (eg. misspelling, undefined frames, handlers, and other variables) will be detected with an alert when you close the script window after entering and "ending" the script. However, many bugs can also go undetected until someone stumbles over them. You should allow sufficient time to de-bug your application, using a variety of people (esp. children) to play through the entire application, before committing it to publication.
Movie scripts are often for identifying variables/functions that are to be 'global', that is: active and TRUE or FALSE throughout the movie or related sequence of movies until defined otherwise. Movie scripts generally start with the 'handler': "on startMovie" or "on stopMovie", followed by lingo definition of the variables, and "end".
Scripts and their Lingo statements can be entered manually through the score script window by double-clicking the particular frame of the script channel or the particular sprite cell to which they will be attached. Or the script window can be opened by selecting a script channel frame or sprite cell(s), and then clicking on the long gray rectangle near the top of the score window. To open multiple script windows, Option-click the arrows in the script window.
Scripts that have been already written or used are available to be selected and entered in open script windows from the score window script pull-down menu. You can also choose 'clear' from that pull-down menu to cancel a script function, or 'new' to write a new script for a selected frame or cell that already has a script attached to it. Scripts can carry over to all cast members of the same name or number that are entered into the score unless you select 'new' from the pull-down script menu to write a new script for a particular selected frame or cell.
The elements of many lingo statements are contained in the alphabetical/categorical lingo menu which is available when a script window is open. These 'pieces' of code can be entered and combined directly from the lingo menu to the script window, or used as a basis for manually writing scripts in the script window.
I use a macro program like Quick Keys to record and enter frequently used scripts or lingo statements; this is especially helpful for creating long, complex scripts in the late night hours when typos and memory lapses are more frequent. Using the Copy-Paste extension is also very useful because it allows up to 10 different scripts to be stored on the clipboard.
Another good way for keeping track of often used or important scripts is by keeping a Simple Text page open to copy scripts onto and out of. This 'script log' can then be saved for later use or 'cannibalization' for other hybrid scripts. There are also tons of scripts available online.
There are thousands of lingo statements that are predefined by Director or can be written and defined by the individual users. These are a bunch of simple and frequently used ones (italic words indicate variables to be defined by users).
| on exitFrame | standard handler to initiate event to occur immediately after leaving current frame; "on exitFrame" can be changed to "on enterFrame" to initiate event to occur immediately when playback head arrives at selected frame. |
| go to |
moves playback head to a specified location in the current score or the score of another movie. Related movies should be grouped in the same folder and alphabetically named relative to play-order. Frame locations in a score can be specified by frame #, or by setting frame 'markers' at the top of the score.
Named frame markers can be moved to different frames at any time. Be careful when deleting frames (comm-[) that you don't also delete necessary frame markers. When frame marker names or movies are entered in "go to" scripts, the literal name should be enclosed in quotation marks. Scripts are not case sensitive, though capitals are often used for readability. |
| the Frame | refers to the current frame |
| go to the Frame | loops playback head in current frame |
| the Frame - 1 | refers to the previous frame (the Frame - 2 is two frames previous) |
| the Frame + 1 | refers to the next frame (etc.) |
| go next | moves playback head to next marker in the score |
| go previous | moves playback head to previous marker in the score |
| go loop | loops playback head between current frame and previous marker to the left in the score |
| pause | stops movie in referenced frame (no longer used in Director 6) |
| continue | moves playback head beyond 'pause frame' (no longer used in Director 6) |
| delay | delays the forward progress of the playback head for the specified number of "ticks", but allows continued playing of sound. |
| the timeoutLength | a 'timeout' occurs when the elapsed time between mouse or keyboard actions exceeds the specified or default amount of 'ticks'.
Ticks are a measurement of computer time based on 60 ticks per second. It can be expressed as a total number of ticks, or as number of seconds x 60 ticks. Thus the lingo expressions 3600, or 60 * 60 both equal 60 seconds or 1 minute. The default setting at the start of each movie is 3 minutes or 10800 or 180 * 60. |
| set the timeoutLength to (# of ticks) | useful for setting the amount of time a movie will remain in a paused or looped state before automatically moving to another specified location. |
| when timeout then | defines what will occur when the movie clock reaches the specified 'timeoutLength' |
| set the timeoutLapsed to | resets the movie clock to 0; timeoutLength setting or default still controls the limit of movie clock until timeout occurs. |
| when timeout then nothing | redefines a specified timeout event so that 'nothing' will happen; this is 'true' until the next 'when timeout then' definition. |
Frame Script Example:
| on enterFrame end combined with Sprite Script attached to button "Menu":
on mouseUp
combined with Sprite Script attached to button "Continue":
on mouseUp |
This set of lingo statements written in three separate scripts, but
contained within the same frame, specifies that upon entering the
referenced frame, the movie clock is reset to 0, the timeoutLength
is set to run out at 30 seconds, if (when) the timeoutLength is
reached the movie goes to the frame specified as "exit", and the movie is paused during the current
frame.
The movie clock is still 'ticking' away during a pause. If the user mouse-clicks the button "Main Menu" during the pause and before the timeoutLength runs out, the movie will go to the frame "menu" of the movie "Fork". If the user mouse-clicks the button "continue" during the pause and before the timeoutLength runs out, the movie will move out of the paused state and proceed to the next frame. These related scripts are useful for allowing a viewer to stop, perhaps to read text at his/her own speed (within the timeout limit), and to choose to continue or return to a menu. If the viewer looses interest, the movie will exit automatically after the specified time, in this case, 30 seconds. |
| unLoadMember (castmember # or "name") | clears specified preloaded cast member(s) from memory so that movie can play better. |
| unLoadMember 16 | clears castmember #16 from memory |
| unLoadMember 4, 22 | clears all castmembers from #4 through #22 from memory |
| random | defines numeric limit/range of property to which random is applied |
|
on exitFrame end |
Upon leaving the current frame, this script randomly resets the foreground color of sprite 18 to any of the 256 colors in the system palette. The playback head is told to loop continuously, entering and exiting only within the 'current' frame, so that the forecolor of sprite 18 is continually being reset to a random choice from the system palette. |
| the text of cast (# or name) | Determines the 'string' that is the text contained in an editable text castmember. Useful for displaying messages, or recording or responding to what a user types on the keyboard. |
|
on keyDown end |
if the last key entered was 'return' (perhaps following a text data entry requested by text castmember 23 to "Please enter your name and phone number followed by the 'return' key"), then the text of castmember 23 is replaced by the text "Thanks!". This change is true until the movie is closed and opened again, or the text is reset by lingo. |
eg. Sprite Script attached to 'check box' button:
|
on mouseUp end |
if the user mouse-clicks this button (in correct response to a question), the specified text cast member (which up til then contained no text) now contains and displays "That's Right !!!" |
|
on enterFrame end |
causes computer to 'beep' as long as mouse button is depressed. |
| play (frame # or "name", movie "name", etc.) | plays specified frame or movie; then if play command was issued by frame script, playback head returns to the next frame automatically. If play command was issued by a sprite script, playback head returns to the same frame. |
| play done | when a "playing" movie reaches a frame with the "play done" script, playback head returns to the frame (or frame immediately after - see above) where the "play" script was originally issued. |
| if the key = "r" and the commandDown then restart | restarts computer when user presses command-r |
| if the key = "q" and the commandDown then quit | quits application when user presses command-q |
| if the key = "d" and the optionDown then shutDown | shuts down computer if user presses option-d |
Sound Scripts
| sound fadeIn (channel #), (# of ticks) | fade in sound in specified sound channel over course of specified time (expressed in ticks) |
|
on exitFrame end |
sound in channel 1 fades in during next 3 seconds (180 ticks), while sound in channel 2 fades out during next 4 seconds (240 ticks) |
| sound stop 1 | stops the sound playing in channel 1. |
| set the soundLevel to 5 | resets the sound volume of computer to 5 (out of 1-7) |
| set the volume of sound 2 to 203 | sets the sound volume of sound in channel 2 to 203 (out of possible 255 - 0 is mute) |
| if soundBusy (2) then go to the frame | if sound is playing in channel 2 then the playback head loops in the current frame allowing sound to finish before proceeding. Sound will not play during a paused frame or when playback head is told to go to another location or movie. |
| if soundBusy 1 then sound stop | if sound is playing in sound channel 1 during selected frame, then sound is terminated. |
| sound playFile 4, "Rub-a-dub" | plays sound file (AIFF or WAVE) "Rub-a-dub", which is external to Director movie, in "channel 4". Normally there are only 2 sound channels available to Director, but this command allows for sounds to be played from up to 8 channels, though playback/RAM can be compromised. |
Cursor Scripts
|
cursor 0 cursor -1 cursor 1 cursor 2 cursor 3 cursor 4 cursor 200 |
resets cursor to specified default cursor (usually arrrow) arrow I-beam crosshair crossbar watch invisible/inactive |
|
on enterframe end |
If the default cursor is over the sprite of channel 8 during or after the frame then the cursor becomes a custom cursor of castmember 7 which must be a 1-bit, B/W 16 pixel x 16 pixel pict. If the cursor is over the sprite of channel 4 during or after the frame, then the cursor becomes a custom version of castmember 9. Otherwise, the cursor is changed to the crossbar (3).
Note: when writing 'if . . . then' statements, it often works better to hit 'return' before the 'then' part of the statement. Both indentation and function are often more correct. |
Rollover and Case Scripts
|
on enterFrame end |
This script assumes that all affected sprites have first been puppetted.
If the cursor rolls over any sprites in channels 6-9, the movie goes to and
plays the specified frame, then returns to the frame where the
rollover occurred. If the cursor rolls over sprite in channel 10, the
playback head goes to movie "Fly" and proceeds from there.
Notice the balanced, nested structure of "ifs", "elses", and "end ifs". In this form of script, all the "if" statements should be balanced out with "end if"s. |
|
on enterFrame end |
This can be expressed more compactly using the "case" statement to do exactly the same thing. Note how "otherwise" replaces "else" in this version. |
Puppet Scripts
| puppetSprite 12, TRUE | makes the sprite inchannel 12 a puppet so that it can be controlled separately by lingo. This remains True until |
| puppetSprite 12, False | removes puppet condition from sprite 12 |
| puppetSound 1, "Bark.aif" | plays sound file "Bark.aif" in sound channel 1; overides any other sound currently playing in channel 1. |
| puppetSound 0 | stops all puppetSounds; returns control back to score sound channels. |
| puppetPalette "Metallic" | resets movie's palette to "Metallic" until command |
| puppetPalette 0 | returns palette to prepuppet status |
|
on enterFrame end
on mouseDown
on mouseUp |
If the cursor 'rolls over' puppetSprite 5, the foreColor of puppetSprite 5 is lightened 2 shades, causing it to appear to "glow"
On the mouseDown of the button this script is written for, puppetSprite 5 is "de-puppetized" After the sprite has been de-puppetized, the movie can move to another frame ("bugout") without carrying along the complications of a puppetted sprite. If possible, all sprites should be de-puppetized before moving to a new part of the score. |
|
on exitFrame
|
|
|
on enterFrame end | Upon entering the frame, the sprite of channel 8 is declared a puppet. That puppetSprite (8) is then defined as 'moveable' by the user (dragging it with the mouse). If that same sprite 8 is then moved across the screen so that it intersects the boundary of the sprite in channel 15, then the playback head moves to the frame "X". |
|
on exitFrame end |
Upon exiting the frame, the sprite of channel 6 is declared a puppet. That puppetSprite (6) is then defined as 'moveable', but constrained within the boundaries if sprite 14.
If that sprite 6 intersects sprite 9, then sprite 6 is no longer constrained within the boundries of sprite 14. This can all occur while the frame is looping. |
|
on mouseDown end |
When the mouse button is depressed (perhaps while over a particular shape or area on stage, the sprite of channel 16 is declared to be a puppet, then reset to the same screen coordinates/location as the current mouse cursor's position. The computer beeps 2 times. The stage is updated. |
|
on mouseDown end |
This script would probably be used during a single-frame loop. While the mouse button is depressed puppetSprite 7 is 'attached' to the cursor, and its castmember is continuously switched between two other cast members (14 and 15) which seem to "buzz" as they follow the cursor around. The stage is updated continuously to reflect the changes. |
|
on mouseUp end |
Another script to be used during a single-frame loop. This enables sequential exchange of cast members (as for a slide show) through cast member 26. |