Good Scripting Habits; Basic Debugging - MACROMEDIA DIRECTOR MX 2004-DIRECTOR SCRIPTING Reference

Director scripting reference
Table of Contents

Advertisement

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
-- 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

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.
84
Chapter 4: Debugging Scripts in Director
structure and repeat loop clear:
if...then
instead of
newNumber
.
ABC

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Director mx 2004

Table of Contents