84
Chapter 4: Debugging Scripts in Director
Good scripting habits
Good scripting habits can help you avoid many scripting problems in the first place.
•
Try to write your scripts in small sets of statements and test each one as you write it. This
isolates potential problems where they are easier to identify.
•
Insert comments that explain what the script statements are intended to do and what the
values in the script are for. This makes it easier to understand the script if you return to it later
or if someone else works on it. For example, the comment in the following statements make
the purpose of the
if...then
structure and repeat loop clear:
-- Lingo syntax
-- Loop until the "s" key is pressed
repeat while not(_key.keyPressed("s"))
_sound.beep()
end repeat
// JavaScript syntax
// Loop until the "s" key is pressed
while(!_key.keyPressed("s")) {
_sound.beep();
}
•
Make sure that the script’s syntax is correct. Use the Script window’s pop-up menus to insert
pre-formatted versions of scripting elements. Rely on the API topics of this reference to check
that statements are set up correctly.
•
Use variable names that indicate the variables’ purpose. For example, a variable that contains a
number should be called something like
newNumber
instead of
ABC
.
Basic debugging
Debugging involves strategy and analysis, not a standard step-by-step procedure. This section
describes the basic debugging approaches that programmers successfully use to debug any code,
not just Lingo or JavaScript syntax.
Before you modify a movie significantly, always make a backup copy. It may help to name the
copies incrementally, for example, fileName_01.dir, fileName_02.dir, fileName_03.dir, and so on
to keep track of the various stages of a movie.
Identifying the problem
It might seem obvious, but the first thing to do when debugging is to identify the problem. Is a
button doing the wrong thing? Is the movie going to the wrong frame? Is a field not editable
when it should be?
You may also want to determine what you expect a particular script to do, and then compare your
expectation with what the script actually does. This process helps you clearly define your goal and
see what parts of the goal are not being met.
If you copied a script or a portion of a script from another movie or from a written example,
check whether the script was designed for some specific conditions. Perhaps it requires that a
sprite channel is already scripted. Maybe cast member names must follow a specific style
convention.
Summary of Contents for DIRECTOR MX 2004-DIRECTOR SCRIPTING
Page 1: ...DIRECTOR MX 2004 Director Scripting Reference...
Page 48: ...48 Chapter 2 Director Scripting Essentials...
Page 100: ...100 Chapter 4 Debugging Scripts in Director...
Page 118: ...118 Chapter 5 Director Core Objects...
Page 594: ...594 Chapter 12 Methods...
Page 684: ...684 Chapter 14 Properties See also DVD...
Page 702: ...702 Chapter 14 Properties See also face vertices vertices flat...
Page 856: ...856 Chapter 14 Properties JavaScript syntax sprite 15 member member 3 4...
Page 1102: ...1102 Chapter 14 Properties...