
info/how to: |
Basic Scripting in Director Lingo - Navigation, Making things clickable, making buttons...The following information assumes that you have used Director, know what frames, sprites, and channels are, are familiar with the score window, and know what the red playback head is.
Lingo is the scripting (or programming) language native to Director. With lingo you can write little scripts and attach them to things. You can decide what causes the script to execute (to start up and do what it's supposed to do). Commonly, scripts are attached to frames or to sprites (there are other places to put scripts, but they are beyond the scope of this explanation).
You attach a script to a frame by double-clicking in the desired frame in the scripting channel. The scripting channel is the channel right above the grey counting bar in the score. When you double-click on a frame in that channel, a blank scripting window opens up. Often it will not be entirely blank, but will prompt you with the following: on exitFrameWhy does it prompt you with the above? It is suggesting the most common trigger event that starts off frame scripts, which is the event that lingo names "exitframe." An "exitFrame" is when the playback head leaves the current frame as it plays through the director movie. "exitFrame" is the event that would have to happen to make the above script execute --- it triggers the script to run. "on exitFrame" means: when the director playback head reaches this frame and leaves it, then do whatever lines of script follow, up until the "end." So you will notice that many frame scripts start with "on exitFrame" and end with "end" You always need "end" at the end of a script to let director know that it's (you guessed it) the end of the script.
If we wanted to set up a director movie that waits for the user to click on a sprite before going on to the rest of the movie, we would put the following as a frame script in the frame we want director to wait on:
The above script is triggered when director leaves the frame. The script makes director go back into the frame. As soon as director plays the frame and goes to leave it, it is send back into the frame. Etc. We can think of this script as setting up a loop over a single frame. Now that we have director stuck in that frame, we can put a sprite in that frame to serve as our button. We need to loop over this frame because that will allow the user time to click on the sprite serving as our button. Even though it may look like Director is not playing while it is looping over the frame, you will notice that Director's play button for controlling the movie will still be down. The fact that Director is still playing while it is on one frame allows Director to detect when the user clicks on the sprite serving as our button. So now we have a sprite in the same frame as the script that is making Director loop. Now we want to attach a script to that sprite.
There are several different ways to attach a script to a sprite, and some of these differ depending on which version of Director you have. Scripts attached to sprites are called sprite scripts. Here I will link to pages showing how to attach scripts in Director 7 (which is similar to 6) and in Director 8: attaching a script to a sprite in Director 6 & 7Once you have the script window open (from attaching or starting a script), you may notice a prompt like this: on mouseUpWhy does it prompt you with the above? It is suggesting the most common trigger event that starts off sprite scripts, which is the event that lingo names "mouseUp." A "mouseUp" is when the user releases the mouse button after clicking. In the above sprite script, "mouseUp" is the event that has to happen to make the script execute -- it is the event that triggers the script to run. "on mouseUp" means: when the user presses the mouse down and then releases it, then do whatever lines of script follow, up until the "end." So you will notice that many sprite scripts start with "on mouseUp" and end with "end." You always need "end" at the end of a script to let Director know that it's (you guessed it) the end of the script.
To make our sprite clickable, we will use the following script, which will, when the user clicks on the sprite, jump the Director movie forward to frame 101 (in which, let's say, you are planning to start an interesting animation of gorillas eating leaves):
back to top
A better way to send users to another place in the director movie is to jump to markers rather than to frame numbers. In the score, immediately above all the white channels above the grey counting bar that are divided into frames is a channel that is totally blank and does not have the frame lines dividing it. This channel is the marker channel. Markers are little triangular flags you can add to the channel and use to mark off starting points for different sections in a director movie.
To create a marker, you just click once in the marker channel above the frame you want the marker to be in. After you click, a little triangular marker will show up, and director will be ready for you to type in a name for the marker (always name your markers). Using markers is usually preferable to using frame numbers because markers are easy to adjust and correct, while frame numbers are chained to the frame sequence, which is inconvenient if you delete or insert frames into the score. So instead of the script on the sprite sending the user to frame 101, it would be preferable to create a marker over frame 101, name the marker something, and then use the marker name in the script.
Assuming I named the marker over frame 101 "green", this is the script you would put on the button sprite to jump the user over to the animation (starting in frame 101) of gorillas eating leaves:
So the above script jumps the user to the marker named "green" when they click on the sprite that has the script on it. |