READING: From Director - Scripting Dictionary: (Click on the + in Director Scripting Reference)
2 - Director Scripting Essentials: Pages 4-25
object based; tuned for multimedia and animation
like driving using only the brakes, b/c the gas
pedal is stuck on the floor
The script window where you enter your programs
The message window that you can use to observe the
Vocabulary: A lot; we will learn them on demand.
- Language constructs
(integers, strings, floats)
arithmetic, (+ - / * mod)
comparative (> >= = <= < )
string (& &&)
logical (and not or)
statements (if; then; while; etc)
- keywords (member; sprite; the; field; movie; etc)
- commands (quit; go to; set; etc)
- Objects (predefined)
- properties of objects (text, color, location, etc)
- computer-generated events (exitFrame, idle, etc)
- user-generated events (mouseUp; mouseDown; etc)
handlers (on mouseUp; on mouseDown; on idle;
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)
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:
set the text of member 23 to "Ouch" --deceivingly
similar to English
set the text of member 23 = "Ouch" --mixing
Let's practice Director's computing engine. Bring up the Message window (command-m) and type each of the lines to see what you get.
-- Welcome to Director --
put "Hello World"
x = 3
x = "Hello World"
put x && x
x = 3
put 2*(x+1) mod x
put pi > x
put x >= pi
put x >= pi or pi > x
if pi > x then _movie.quit()
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
addition, the file contains two text fields that behave as buttons, due to the script that is attached to them:
A "Start" button with script
_movie.continue() // just as an example, do not use this commend in the future
and a "Stop" button with script
_movie.pause() // just as an example, do not use this commend in the future
The _movie notation means that continue() and pause() are methods that belong to the movie object, one of the fundamental objects that exist in Director.
that never again will you
need to use pause() and continue() - they are used to shut down and
jumpstart the whole Director engine. But they are simple enough for introducing Lingo
STATEMENTS: 1. The if-statement
File "interact02.dir" contains
in addition another text cast member 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. Make it be continuous by moving the sound channel sprite start at frame 1.
Note that the sound will finish after a while. Make it loop from the beginning by clicking the "Loop" checkbox in the Property of the "8BITWIND" sound cast member.
File "interact03.dir" has script in "Volume" that
introduces the if-statement, another control structure:
if (_sound.soundLevel > 4) then
_sound.soundLevel = 4
put _sound.soundLevel -- display it in the message window
_sound.soundlevel = 7
The script allows you to change the sound volume and observe the
changes in the message window. As with _movie, the _sound notation means that soundLevel is a property of the object sound, another of the fundamental objects in Director. We can tell that is is a property and not a method because there are no parentheses () after its name.
It also has another button "Sound On/Off" with script that introduces
_sound.soundEnabled = not (_sound.soundEnabled)
Exercise: Comment this line off by using -- and rewrite it using the if-statement.
Note the automatic indentation that provides feedback on the way
your program is expected to behave.
File "interact04.dir" introduces the
concept of changing two properties (text and color) of
text members; instead of observing in the message window
happens, the changes affect the text of "Volume":
member("Volume").text = "HIGH VOLUME"
can also change its default color of a member like that:
= rgb(255,0,0) -- red
member("Volume").color = rgb("#00FF00") -- green
for the other button, its name changes depending on whether
sound is enabled or not:
if (_sound.soundEnabled = TRUE) then
member(7).text = "Solar Wind"
member(7).text = "Cosmic Silence"
Note that the two sound-related buttons behave differently. What is the difference?
Should the text on the button inform you of what is happening now, or what will happen if you click it?
Decide what should be better and fix the appropriate button by changing the code.
YOUR FIRST GAME
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 :-).
It can also "speak" to you - can you find the command that does that?