Debugging

A large portion of the time spent writing a script is often spent on debugging—that is, finding any bugs and errors in the script and correcting them so that the script runs flawlessly in an execution environment.

There are several ways to test and evaluate your script’s behavior.

 

Stepping Through a Script

One of the most obvious but still useful techniques for testing a script is to simply step through its evaluation one line at a time. This gives you the opportunity to view the effect of each command as it’s executed—typically, scripts execute too quickly to observe what’s happening.

When a script is loaded into the MP Bar, you can step forward one line at a time by clicking the Next Step button.

In the MP Editor, you can enable debugging mode by clicking the Debug button. When you do this, the Next Step button will appear in the editor window, allowing you to step through the script.

 

Debug Mode

The MP Editor has a debug mode that you can enable. Debug mode provides several benefits for testing:

Debug mode shows variable values (left column) and current argument values.

These three items provide most of the tools you need to discover errors in your script. Debug mode only works with a single script. This means that if a subroutine is called, you will not see any changes in the MP Editor window until the subroutine returns and execution continues in the current script. To view values in parent scripts and subroutines as a script executes, use the MP Watcher.

 

To Enable Debug Mode:

  1. In the editor, click the Debug button. In debug mode, all arguments will become read-only and they will display their current values.

  2. Run the script or step through it using the controls at the top of the window.