| |
|
|
||||
![]() |
||||||
| |
|
|||||
|
Writing MaxScripts The process of writing a script in Max is quite different than writing one in other interpreted languages. Without the benefit of a substantive debugger, the code writing process breaks down into three stages. First, the code must be written into Max’s real-time interpreter, and the programmer watches it execute line by line. If a line does not perform as intended, it is modified and then executed again. The next step is to save this code into a script file, which typically involves wrapping the code with a simple interface description. With this interface description, one can proceed to the final stage, which is executing the script and making sure it performs as intended. If it doesn’t work, the user must return to stage one to attempt to reproduce and fix the error. Inside Max there is a window called the Listener, in which you can type commands that are interpreted and executed. Return values are printed to the window for each command that is issued. By typing in the desired functionality line by line, you can ensure that your algorithm is working as desired. Variables can be examined at each step by printing them out into the listener window. While admittedly this process seemed a bit clunky at first, it was easy to get used to.
Once a section of code has been debugged, it is added to the script and saved to disk. This script will usually need to define a GUI interface, especially if the user needs to enter options (such as the file name to save to). Defining an interface is easier in Max than in any other language or tool I have used. Alternatively, if no interface is required, the script could just be a sequence of commands that execute when the script is run. An example would be a script that rotated all of the objects in a scene 90 degrees. Such a script could be linked to a custom button inside the Max GUI for easy access. Once a script is created with a GUI, it can be loaded into Max through the Utility panel. Clicking the Run Script button prompts the user to specify the MaxScript file to load. When your utility is loaded, its GUI is added to the Utility panel and it looks and acts as if it were a part of Max’s base code. If an error occurs during either the load and parse or the execution of a script, Max pops up the script source in an editor window and highlights the line on which the error occurred. Fixing an error in a script can be frustrating, because it usually involves going back to the Listener, and typing your algorithm in line by line waiting to see the error. Only rarely was I able to debug the code by looking at the runtime error information supplied by Max. However, I did notice that as my familiarity with scripting increased, the time required for debugging decreased substantially, and I am now quite comfortable with the process. |
|
|