Director Tutorials

 

Lingo & Programming Terminology

Arguments: information that gives further clarification to a command.
For example: go [whichframe]
set [what] to [what]
Arguments are values that are passed onto parameters (see parameters).

Commands: instructions that tell your movie to act on something or do something while the movie is playing.
For example:       beep tells Director to make a beep sound.
                               go tells Director to jump to a certain frame/marker or movie.

Comments: notes you can place within a script that help explain statements or provide other general information about the content of a script.  These notes are ignored by the computer when executing the script. A double dash (--) is placed before a comment to identify it as such. It is a good idea to provide a comment before defining a global variable so it is clear what the variable is.
For example
-- hiScore records the highest score achieved in the game
global hiScore

Conditional statements: statements in programming that allow you to test for conditions (such as TRUE/FALSE) and execute commands based on those conditions
For example:
if soundBusy(1) then go the frame
The condition was not written as soundBusy(1) = TRUE. By leaving out the value (i.e. = TRUE), Lingo assumes a TRUE value.

Constant:
data that doesn't change during a movie - has a 'constant' value.
For example:       FALSE, EMPTY
member(1).text = "empty"        puts the word 'empty' into the text cast member.
member(1).text = EMPTY         clears everything (all text) from the cast member

Events: actions that occur while a movie is playing.
For example:       exitFrame is when the playback head exits a frame
                               mouseUp is when the mouse button is released

Expression: segments of code that result in a value, for example 1 + 1.
Expressions exist within statements.

Function: Lingo that provides information on a particular state or condition/value.
For example:      the time returns the current time
                              the name of member returns the cast member's name
                              the key returns the key that was pressed last.
A function (or top-level function) can also instruct a movie to do something while the movie is playing. These functions always have parentheses occur at the end of the function. For example, calling the top-level list can have the syntax list().

Handlers: grouping of Lingo intended for execution as a unit, begins with a keyword on. Event handlers are a unit of code that executes when an event occurs
For example:        on mouseUp
                              : on enterFrame

K
eywords: the 'nouns' of programming - help further define aspects of scripting.
For example:        the, cast, field, end

List: a particular type of variable that can contain several discrete units of data at once. Each unit, known as entries, can be manipulated without affecting the others. Known as Arrays in JavaScript Syntax.

There are 2 types of lists:
Linear list: is a series of single values in sequence. Each item, separated by a comma, is a single unit of data.
e.g. ["Advanced Multimedia", "Computer-Aided Design", "Digital Design Techniques"]

Property list: contains 2 units of data for each entry, separated by a colon (:) One unit is the value (data to be stored, retrieved or modified), while the other serves as a property (another value used primarily for organising purposes).
e.g. ["Jack":95, "Jill":50, "Peter":65, "Sarah":75]

For more info, see the The Power of Lists - List Lingo technote.

Loops: the process of continually repeating a section of a script/movie, while a certain condition is true or for a specified number of times.
Example 1
repeat while the mouseDown
  nothing
end repeat


Example 2
repeat with x = 1 to 10
  sprite(x).visible = 1
end repeat


You can exit a loop by using - exit repeat.

Messages: are notices that Director sends to scripts when specific events occur in a movie. To run the appropriate set of Lingo statements at the right time, Director must determine what is occurring in the movie and which Lingo to run in response to the event. Director sends messages to indicate when specific events occur in a movie, such as when sprites are clicked, keyboard keys are pressed, a movie starts, the playback head enters or exits a frame. Handlers within scripts contain instructions that run when a specific message is received.

For example, when the playback head enters a specific frame, the enterFrame event occurs and Director sends an enterFrame message. If a script contains an on enterFrame handler, the statements within that handler will run, because the handler received the enterFrame message.

Methods: terms that either instruct a movie to do something while the movie is playing or return a value, and are called from an object. For example isBusy (in MX 2004+) in the context of sound(1).isBusy(), is a sound channel method that determines if a sound if playing (TRUE) or not playing (FALSE) in channel 1. Is similar to a function but is always called from an object.

Object-Oriented Programming (OOP): a programming approach that groups together data and procedures (sequences of instructions ) into a single unit (an object). Lingo is an OOP language.

Object: any unit of Lingo script that is designed to both receive input and produce a result. Each event handler is an object, since it takes input (message of an event) and produces something (whatever scripted actions it contains).

Operator:
a character or word that acts or 'operates' on one or more elements. They can be used for calculations (+, - , /, *), assignment of values (=, to, into) or comparison (<, >, =, <>)
For example:        x = 10
                               put 10 into x

Logical operators:
: combine Boolean values and produce a Boolean result. A Boolean value is TRUE (=1) or FALSE (=0). In Lingo, positive or negative integers is TRUE, 0 is FALSE. Important terms used in logical operators include AND, OR, NOT.

Concatenation operators:
used to combine strings. These include & and &&.
&&
combines the strings with a space in-between them.
For example:
put "dean" && "utian"
-- "dean utian"


Parameters: Are variables used to give added flexibility to handlers/behaviors.
For example:
-- sprite behavior to follow cursor horizontally
on exitFrame me
  sprite(me.spriteNum).locH = the mouseH
end


The term me is a parameter that together with spriteNum indicates the sprite number to which the behavior is attached. The word me has no special magic and the above behavior would work in exactly the same way if me was replaced by deano.

Parameters can be changed when calling a handler (referring to a handler in code).
For example
on calcVolume value1, value2, value3
  put value1 * value2 * value3
end


You can then pass on values (arguments) to parameters by typing the following in the Message window:
calcVolume 2, 2, 3
-- 12


See the Using me and Other Parameters in Lingo technote

Properties: attributes that define an object. Sprites, cast members, even behaviors can have properties. For example, colorDepth is a property of a bitmap cast member. You can set properties of scripts by using property variables (see variables below).

Procedural programming: code structured as a list of instructions telling a computer, step-by-step, what to do, usually having a linear order of execution from the first statement to the second and so on to the end.

Statement: One executable line of Lingo.

Symbol:
are user-defined constants and have a # at the start of the name. They combine the speed of integers and the descriptive property of strings. Comparisons using symbols can usually be performed very quickly, providing more efficient code.
For example, the statement
userLevel = #beginner
runs more quickly than the statement
userLevel = "beginner"

Symbols can't contain spaces or punctuation. A string can be converted to a symbol by using the symbol() function, and can be converted back to a symbol by using the string() function.
For example
x = symbol("beginner")
put x
-- #novice


x = string(#beginner)
put x
-- "beginner"


Variable: a storage 'holder' for data that can change/vary in a movie. Variables exist entirely in RAM. There are different data types of values variables can hold:

Data Types
integers: whole numbers e.g. 1, -5
floats: decimal point numbers e.g. 1.5, -0.89
strings: text e.g. "dean", "Multimedia design"
symbols: e.g. #dean, #123
boleans: e.g. TRUE or FALSE, 1 or 0
lists: hold multiple pieces of data at once, which can be integers, floats, strings, symbols or a combination of all. e.g. [1, 2, 3], ["abc", 1.2, #name]

Local variables - holds data available in current handler being executed.
Global variables - holds data whose value can change and be accessed throughout the movie. Globals must be declared as such using the global keyword.
Property variables - hold data only for the particular object it is attached to. Like globals, properties need to be declared, using the property keyword.

For more info, look at the Variable Types - Local, Global and Property Variables technote.

Assigning a value to a variable:
put value into variable -- old, dated approach
set variable to value -- verbose approach
variable = value -- best approach


Rules for variable names
They have to be single words, you cannot have spaces in a variable name.
You cannot start a variable name with a number.
Variables cannot have ? character in the name.