Error Messages

When MAXScript detects a runtime error in your script, it displays an error message and prints diagnostic information to the Listener output pane.

If the error occurs in a controller script or rollout panel script, the error message is displayed in an Alert Box window and is also printed in the Listener output pane.

3ds Max also features a MAXScript Debugger which provides a more advanced toolset for dealing with errors and monitoring variables.

Listener Call Stack Trace-Back And Editor Error Highlight

The diagnostic information is in the form of a call stack trace-back which can help determine the cause and location of the error in your code.

The call stack trace-back shows

  • The nesting of called MAXScript functions at the point of error, deepest ones first to outermost ones last;

  • The filename, position and line number the error occurred at;

  • The values in all the local variables and function parameters at the levels they are declared or first used.

Note that for loops produce separate entries in the call stack trace-back and include a variable dump for the loop variable and any locals in the loop body. This is because a for loop body represents a variable scope.

As a further aid in locating the error, MAXScript highlights the line in which the error occurred in an MAXScript Editor window if the running code was compiled from a source file (any code not entered directly in the Listener). If the source file is not currently open in the MAXScript Editor, MAXScript opens the file in a new tab. The line containing the code in which the error occurred is highlighted and scrolled into view.

The error message is either displayed in an Alert Box window or the Listener window. In both cases, the Alert Box or Listener window is brought to the front and the MAXScript Editor window containing the code causing the error is immediately behind.

Compile and runtime error messages reported in the Listener output pane are preceded by the comment symbol "--", so you can reselect and evaluate code in Listener that might have embedded error messages and not have them cause syntax errors.

In the following figure, an Editor and a Listener window are shown where an error was detected while running the script.

The error occurred in the highlighted line in the Editor window.

Looking at the call stack trace-back, we see the error occurred when the for loop variable i is equal to 100.

In the line in error, the position of the object from array b with index i is being set.

After further investigation, it was found the array b only had 99 elements defined.

Thus element b[i] contained the value undefined , which resulted in the error as there is no position property associated with undefined .

ADVANCED INFORMATION ON THIS SPECIFIC ERROR:

The correct way to avoid this particular error would be to use 'for i = 1 to b.count do' to ensure the loop never exceeds the number of objects in b, and also divide by b.count in the line 'z=360.0*i/b.count'.

Obviously, the above "mistake" was introduced to cause an error for demonstration purposes.

The script itself tries to place all selected objects in a circle with radius the Radius around the point pos0.

Script Controller Errors

In the following figure, an error dialog and script controller dialog are shown.

An error was detected while running the script assigned to a script controller.

This error was caused by the deletion of object Box001, whose position was used directly in the script.

The MAXScript Listener shows the following call stack trace-back for this error:

ADVANCED INFORMATION ON THIS SPECIFIC ERROR:

Since 3ds Max 8, the above way of accessing object properties is considered obsolete and a Bad Practice exactly because it can cause a large number of errors when a referenced object is deleted or cannot be found for other reasons (for example when an object with a Script Controller is brought into a scene via XRef).

The correct approach to avoid this specific kind of error would be to use a Variable assigned the Position track of Box001. Deleting the Box001 would not cause an error in the controller. As an added bonus, the controlled object would update its position when Box001 is moved along Z automatically.

Please see Script Controllers for details.

See Also