O'Reilly logo

Lingo in a Nutshell by Bruce A. Epstein

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

A Simple Sample Debugging Session

You should become adept at using the Debugger, and there is no substitute for practice. Start with a fresh Director movie that doesn’t have any scripts. Use:

          set the alertHook = 0

to cancel any alertHook in effect to make sure that error dialogs are displayed.

Suppose we want to create a handler that returns a list of numbers from 1 to 10.

Type the following into a movie script cast member exactly as shown. (There are supposed to be errors; this is a debugging example.)

Example 3-21. A Simple Sample Debugging Session: Initial attempt to create handler

on createList
  repeat x = 1 to 10
    add myList, x
end

Before closing the script window type createList in the Message window and press Return. You should get a "Handler not defined: createList" error. Why? Because we haven’t compiled the script, so Director doesn’t know about our new handler yet.

Close the Script window to compile the script. Oops, we get an "Expected WHILE or WITH" error. What is wrong? Click the Script button in the error dialog to reedit the script. We’ve mistyped the repeat command and need to add the word with. Correct it as follows.

Example 3-22. Improved repeat loop including "with"

on createList
  repeat with x = 1 to 10 -- Correct this line
    add myList, x
end

Close the script again; this time we get an "Expected END REPEAT" error. We forgot the end repeat for our repeat loop.

Example 3-23. Improved repeat loop including "end repeat"

on createList repeat with x = 1 to 10 add myList, x end repeat ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required