Lingo 1 Tutorial: Introduction to Interactivity

READING: Chapter 9 of D8D (Chapter 8 is a little too complicated for now)
In the (optional) using_director_mx.pdf reading :
Pages 389-393 on Lingo terminology and syntax
Pages 402-404 on variables
Pages 408-410 on operators

The programming environment of Director
  • The Language: Lingo;
    object based; tuned for multimedia and animation
  • The Experience:
    like driving using only the brakes, b/c the gas pedal is stuck on the floor
  • Cmd-0: The script window where you enter your programs
  • Cmd-M: The message window that you can use to observe the action
  • The Vocabulary: A lot; we will learn them on demand.
    To be precise, but also more confusing, Lingo has:
    • commands, (quit; go to; set; etc)
    • properties of objects,
    • operators:
      arithmetic, + - / *
      comparative > >= = <= <
      string & &&
      logical and not or
    • keywords (member; sprite; the; field; movie; etc)
    • control statements (if; then; while; etc)
    • functions aka handlers
    • events (mouseUp; mouseDown; idle; etc)
    • event handlers (on mouseUp; on mouseDown; on idle; etc)
  • Most of the time it will be irrelevant what a particular "thing" is... basically because it can be confusing (e.g., mouseDown is an event; on mouseDown is a handler; the mouseDown is a function; etc)
THE SYNTAX

The old syntax of Lingo is deceptively simple and English-like. We will use Java-like syntax.
All of the expressions below are understandable by Director:
member(23).text = "Ouch" --dot syntax (like Java and JavaScript)
set the text of member 23 to "Ouch" --deceivingly similar to English
set the text of member 23 = "Ouch" --mixing the two

LINGO FOR CAST MEMBERS (only, for now)

File "interact01.dir" contains only two cast members (the sun and the earth) and an animation of the earth rotating around the sun done in the score. Note that I have named the files with short names and the .dir so that they can execute on both Macs and Windows, old and new.

In addition, the file contains two more buttons (created simply by clicking and dragging with the button tool):
A "Start" button with script
on mouseUp
continue
end

and a "Stop" button with script
on mouseUp
pause
end

continue and pause are part of the "control structures" that every programming language has...

Note that never again will you need to use pause and continue - they are used to shut down and jumpstart the whole Director engine. In fact, Macromedia considers them obsolete and has stopped supporting them. But they are simple enough for introducing Lingo programming.

CONTROL STATEMENTS: 1. The if-statement

File "interact02.dir" contains in addition a cast member button named "Volume" and a sound cast member "8BITWIND". It can be used as a starting point for implementation.
Note that the sound starts every time we jump/start in the score...
File "interact03.dir" has script in button "Volume" that introduces the if-statement, another control structure:
on mouseUp
if the soundlevel > 4 then
soundLevel = 4
put the soundLevel -- display it in the message window
else
soundlevel = 7
put the soundLevel
end if
end

The script allows you to change the sound volume and observe the changes in the message window.
It also has another button "Sound On/Off" with script that introduces boolean properties
on mouseUp
the soundEnabled = not (the soundEnabled)
end

Comment this line off using -- and rewrite it using the if-statement.
Note the automatic indentation that provides feedback on the way your program is expected to behave.

PROPERTIES OF OBJECTS

File "interact04.dir" introduces the concept of changing two properties (name and color) of the buttons; instead of observing in the message window what happens, the changes affect the name of the button "Volume > " and it becomes "Volume >>> "
member(5).text = "Volume >>> "
and "Volume > "
member(5).text = "Volume > "

COLORS

You can also change its default color like that. In the usual Mac palette, White is 0, Black is 255. Memorizing the multiples of 16 will help you:
16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 256
Try to always use 256 colors. Here is how you can use it:
member(7).foreColor = 255 -- black
member(7).backColor = 255 -- red
You can also use the rgb color composition:
member(7).color = rgb(0,0,0) -- black
member(7).bgcolor = rgb("FF0000") -- red

As for the other button, its name changes depending on whether sound is enabled or not:
if the soundEnabled = TRUE then
member(7).text = "Solar Wind"
else
member(7).text = "Cosmic Silence"
end if

File "interact05.dir" shows how the button functionality can be incorporated to any other cast member: The sun starts and the earth stops the movie - if you catch it :-).


Now we're done, examine the file "ROLLING.DIR" on your own.


That's all for starters. Some of these topics are covered more in depth in the text:
Turning off sound with toggling button (Chapter 4, pages 118-120)
Displaying sound status (Chapter 4, pages 120-122)
Non-linear leap button (Chapter 4, pages 116-117)


 

 

Maintained By: Takis Metaxas
Last Modified: August 7, 2007