|
READING: From Director 11 - Scripting Dictionary: (Click on the + in Director Scripting Reference)
Chapter
2 - Director Scripting Essentials: Pages 4-25
- 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.
Lingo
has:
- Language constructs
- variables:
(integers, strings, floats)
- operators:
arithmetic, (+ - / * mod)
comparative (> >= = <= < )
string (& &&)
logical (and not or)
- control
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)
- methods
- Events
- computer-generated events (exitFrame, idle, etc)
- user-generated events (mouseUp; mouseDown; 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
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
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 text fields that behave as buttons, due to the script that is attached to them:
A "Start" button with script
on mouseUp
_movie.continue() // just as an example, do not use this commend in the future
end
and a "Stop" button with script
on mouseUp
_movie.pause() // just as an example, do not use this commend in the future
end
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 11.
Note
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
programming.
CONTROL
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...
File "interact03.dir" has script in "Volume" that
introduces the if-statement, another control structure:
on mouseUp
if (_sound.soundLevel > 4) then
_sound.soundLevel = 4
put _sound.soundLevel -- display it in the message window
else
_sound.soundlevel = 7
put _sound.soundLevel
end if
end
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 11. 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
boolean properties
on mouseUp
_sound.soundEnabled = not (_sound.soundEnabled)
end
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.
PROPERTIES
OF OBJECTS
File "interact04.dir" introduces the
concept of changing two properties (text and color) of
text members; instead of observing in the message window
what
happens, the changes affect the text of "Volume":
member("Volume").text = "HIGH VOLUME"
COLORS
OF MEMBERS
You
can also change its default color of a member like that:
member(7).color
= rgb(255,0,0) -- red
As
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"
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 :-). It also "speaks" to you - can you find the command that does that?
|