• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Lesson 16. Learning Lingo > Creating a Simple Lingo Script

Creating a Simple Lingo Script

Every Lingo script is attached to an element of a Director movie: a sprite on the stage, a member of the cast, a frame of the score, or the movie itself. In this task, you'll create a movie with a button cast member and then attach a script to that button.

Choose File >New > Movie (Windows Ctrl+N, Macintosh Command+N).

This opens a new Director movie. You need to do this only if you already have another movie open.

Choose Modify > Movie > Properties. When the Property Inspector opens, use the View Mode button to view the window in graphics mode.

In the Property Inspector window, make sure that the stage size is set to 640 by 480 pixels and the stage location is set to Centered. Also make sure that the default palette is set to the system palette for your system: System - Win for Windows and System - Mac for the Macintosh. In previous lessons, the settings may have been different; using these settings will help you to follow the steps and the illustrations in this lesson.

Figure .

If the Stage Location pull-down menu seems to have no effect, try selecting Center and then choosing View > Standard View (Windows Ctrl+Alt+0, Macintosh Command+Option+0) or View > Restore View.

The keyboard shortcut for normalizing the stage (Windows Ctrl+Alt+0, Macintosh Command+Option+0) is handy to remember if part of the canvas appears around the stage and you don't want to see it, or if you need to center the stage in the Stage window.

Choose Control > Loop Playback to make sure the Loop Playback command is checked (Windows Ctrl+Alt+L, Macintosh Command+Option+L).

When the Loop Playback command is checked, the playback head returns to frame 1 when it reaches the end of the last sprite in the score. The movie will continue to loop until you stop it.

Open the score and select channel 1, frame 1.

Figure .

If you don't see the sprite toolbar at the top of the Score window, choose View > Sprite Toolbar (Windows Ctrl+Shift+H, Macintosh Shift+Command+H).

Open the tool palette by choosing Window > Tool Palette (Windows Ctrl+7, Macintosh Command+7).

Click the Button tool in the tool palette.

Figure .

Click the stage where you want to place the button.

A button appears where you click, with a blinking insertion point indicating where you can type the button name. Remember that you can reposition the button sprite later if you want.

Type Beep in the Button Text field.

This names the button.


Director is preset to add new sprites to the score with a duration of 28 frames. The length of the sprite isn't important in this task, so you need not worry if your button spans a different number of frames. If you want to have your score look the same as the illustrations, choose File > Preferences > Sprite and make sure the span duration is set to 28 frames.

Select the button sprite in channel 1 of the score and choose New Behavior from the Behavior pop-up menu in the sprite toolbar.

You're creating a sprite script, which affects only this sprite. You'll learn about the various script types later in this lesson.

Figure .

The Script window appears, already containing the Lingo commands on mouseUp me and end. Whenever you create a sprite script, these lines will already be entered in the Script window by default.

Figure .

Type beep in the Script window, at the insertion point, belowon mouseUp.

Beep is a Lingo command that sounds a system beep on the computer.

This is how the script should look:

end ________________ EVERY HANDLER WITH THE WORD END

Here, and wherever you type a Lingo script, you'll want to check the spelling carefully. Director can't interpret Lingo commands that are misspelled or incorrectly punctuated. You can, however, use any combination of uppercase and lowercase letters in your commands. Director does not pay attention to case and would understand this command typed as beep, BEEP, or Beep.

To make it easier to enter commands correctly, you can click the Alphabetical Lingo button or Categorized Lingo button in the Script window and choose from the lists that are displayed. The Alphabetical Lingo button displays a list of all Lingo commands in alphabetical order. The Categorized Lingo button displays the commands organized in categories. When you select a command, it is pasted into the Script window at the insertion point. Because you don't need to type the command, you are less likely to make typing and syntax errors.

Figure .

The Lingo keyword me in the on mouseUp me line is a variable containing information supplied by Director about the current object. For example, the me variable could determine which element on the Stage was clicked to cause a script to run. Director automatically supplies the me keyword in the default sprite and frame behaviors, but its use is optional. Variables are described in detail in Lesson 20.

Close the Script window by pressing Enter on the numeric keypad or by clicking the close box (in the upper-right corner of the Script window on Windows systems or in the upper-left corner on the Macintosh).


Macintosh users: Although pressing Return usually does the same thing as pressing Enter, this is not the case in the Script window. Here, Return starts a new line, just as it does in a word processing application.


Pressing Enter on the numeric keypad enters a script only when the Script window is open. When it is closed, pressing Enter on the numeric keypad plays the current movie.

Look at the Cast window. You now have two cast members: the button cast member and the cast member containing the behavior you just created. The small cog-shaped icon at the lower right of the cast member's thumbnail indicates that it is a behavior. Even though the script is attached to the sprite, it still occupies a slot in the cast. All scripts except scripts attached to cast members appear as cast members.

Figure .

Save your work as Button1 in your Projects folder.



Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint