>>Scripting Fundamentals


Comparison of Lingo to other languages

How similar:

1. Variables, global and local: Variables are storage containers for changing data. Variables in Lingo must be declared before they can be used. Global variables can be called from anywhere within a Director movie; local variables only take effect within the particular script where they are placed. You do not need to declare which kind of data type a variable is in Lingo. In newer versons of Director you may also use properties instead of variables that are specific to the sprite that you attach a behavior to. Properties can be shared between all behaviors attached to a specific sprite.

2. Handlers: Like methods or functions, handlers are useful for naming a set of program instructions that can be called multiple times in the program instead of writing the same sequence of instructions repeatedly in different parts of the program. Many "event handlers" for common "events" like mouse clicks are built into lingo. You may also name your own handlers as in the following example:

on Tickler

if rollOver("Belly") then
sound playFile ("Laugh")


This handler is named Tickler.

3. Looping and Conditionals: The Score Window in Director is useful for creating sprite loops with minimal scripting necessary, however, looping structures and program flow can also be controlled through Lingo if all the sprites are placed in one frame of the score and controlled through lingo. Built in Director behaviors can be used to exit a loop and move to different loop or, alternately, scripted lingo can be written to check for "events" or conditions which would cause the program to exit a loop . (See Lingo code examples of if -then statements in the Lingo Dictionary in Help.)

4. Operators: Lingo uses many of the same comparison operators and math operators as other languages.

* (multiplication)
<> (not equal)
/ (division)
> (greater than)
+ (addition)
>= (greater than or equal to)
- (minus) < (less than)
= (equals)
<= (less than or equal to)

5. Syntax: As with writing in other programming languages, details in Lingo matter--you must learn to use proper lingo syntax. More recent versions of Director have implemented "dot syntax", similar to the syntax used in object oriented programming. Most script examples in "Director Help" include both a non dot syntax and a dot syntax example(both will work).

--sets the cast member in sprite channel 3 to a cast member 22

set the member of sprite 3 to 22

--accomplishes the same thing in dot syntax

sprite(3).member = member(22)

another example:

--makes sprite 3 visible

set the visible of sprite 3 to true

--accomplishes the same thing in dot syntax ( and 1 = true, 0 = false)

sprite(3).visible = 1

6. Comments: Lingo uses double dashes "- -" and the color red to differentiate comments from code. Informative and consistant use of comments will help the development of your lingo scripts.

7. Parent scripts and child scripts: These are a form of lingo specific object oriented programming different from Java or C++.

8. Behaviors: The more common application of object oriented programming in lingo is the writing of behaviors that may be attached to sprites or frames. The use of sprites in Director with attached behaviors makes lingo in effect object oriented, although inheritence, classes, and other aspects of object oriented languages are not used in this case. The shift towards "object oriented" behaviors in lingo often includes the declaration of "properties", which serve a similar function to variables. Properties can be made into customizable parameters each time you attach a behavior to a sprite through the writing of a "property description list." The Behavior Library includes a number of prefabricated behaviors. It can be helpful to look at the lingo for these premade behaviors to learn how to write advanced behaviors.

9. Debugging: As with other languages, developing debugging skills is as important as developing writing skills. Director has a built in Debugger which will point to problem areas in your script and list variable and property values .(Use the lightening icon above the script window to compile your script.) Lingo writers often use the message window (command+m) while scripting to "put" variable contents and track the execution of each line of lingo code. Helping your friends debug is a great way to improve your scripting skills.

The trace icon is darkened at the top of the message window. The trace feature in the message window allows Director to write each line of code as it is executed to the message window. (In this example the program is just looping back to Frame 1)

How different:

1. Scripting vs. Programming: Lingo is a "high level" Scripting language, somewhere inbetween English and more powerful programming languages like C or Java. Supertalk is another similar scripting language to Lingo for the multimedia/authoring application Supercard. Instead of including a list of libraries at the beginning of your script, (as in, for example, a C program) Macromedia has included many commonly used features for you within Director. In the last couple years Macromedia has added a number of lingo commands specific to the Internet. When a Director "movie" is saved as a "Projector", Director saves the necessary compiling code along with the movie to make a standalone application. (Otherwise you must own a copy of Director to run the movie.) If a Director movie is saved as "Shockwave" file it is compiled through the Shockwave plug-in for network browsers. If Director's new "Save as Java" option is used, the movie is converted to a java applet and run off the browser.(This feature is still rather limited and buggy.)

2. Script Location: Director has different places were scripts can be attached which has a strong impact on how the script is executed. Scripts located in the "Movie Script" (mac: command+shift+u, pc: ctrl+shift+u) play when the program first starts up. The movie script is a good place to declare global variables and store handlers, as well as take care of general behind the scenes start up stuff before the Director movie starts to play such as declaring certain sprites visible or not visible. Recently, however, lingo programmers favor a more decentralized approach to scripting with the majority of the script stored in reusable object oriented behaviors. (Instead of doing behind the scenes start-up things in an "On startMovie" handler located in the movie script, prepatory behind the scenes code can be placed in a "beginSprite" handler in a behavior attached to a specific sprite.) "Behavior" Scripts can also be attached to the frame channel and to sprites. Cast member scripts are attached to specific cast members. If a script is attached to a cast member it will always execute when that cast member is activated-- if a behavior script is attached to a sprite it will only execute when that particular sprite is activated. (Thus the same cast member can be reused in different contexts with different behavior sprite scripts attached to it.) Writing behaviors is usually preferable to using cast member scripts. (Care must be taken not to write conflicting cast member and sprite scripts.) Frame scripts located in the Frame Script channel in the Score Window are where scripts which control the location of the playback head are usually located. A script can be attached to a particular cast member by pressing the script icon (writing on paper) icon at the top of the cast member information window.

A movie that exhibits a horizontal distribution of sprites in the Score Window.

3. Puppeting: Director gives you the option of controlling sprites entirely through Lingo with puppeting or through placement in the Score Window. However, more recent versions of Direct implement "autopuppeting", so in effect you dont have to actually declare channels as puppets to control them through lingo.

4. X-tras: X-tras and X-objects are external plug-ins to Director written in C than perform a diverse range of functions. They are often used to interface Director programs with external I/O beyond that of mouse and keyboard.