The Script Editor

Now that you have explored the beginnings of object creation and manipulation, the next step is programming. MAXScript is a programming language at heart, and two of the most important concepts necessary for mastering MAXScript are conditional statements and loops.

At this point, real script writing comes into play. From the Main Menu > MAXScript menu item, select "New Script". A new MAXScript editor window will open. In this window, you can create, edit, save, and load scripts.

Another way to open a new script is the "New Script" button in the MAXscript Utility in the Utilities tab.

Other than the Listener, you can open any number of Script Editor windows and work on multiple scripts at a time, copy and paste code between the editor windows etc.

Thus far in this tutorial, you have been performing all of the script examples in the MAXScript Listener, however when you are writing or editing a script of your own, you will use the Script editor.

The main difference between the Script Editor and the Listener is that the Listener can only evaluate one set of information at a time. In contrast, you can enter long, complex scripts in the Script Editor and evaluate them piece-by-piece or all at once.

Scripts are entered using the same syntax and rules, however they are not executed upon pressing ENTER. In order to execute the entire script, use "Evaluate All" from the File Menu of the Script Editor, or press CTRL+E. You can also execute scripts several lines at a time by highlighting the lines you want to execute and pressing SHIFT+ENTER, or ENTER on the numeric keypad.

Navigating the Script Editor

The Script Editor contains several useful tools for navigating and error-checking large scripts.

Tabs and Indentation

You can use the TAB key to control the indentation in your script. This makes it easier to read the script and to keep track of opening and closing parentheses used to create blocks of commands.

In contrast to some simpler text editors, selecting multiple lines and pressing TAB will not delete the lines but indent them as a block.

To move the selected line(s) back one tab position, you can press SHIFT+TAB.

If you press the RETURN key to add a new line while inside an indented block in your script, the newly inserted line will respect the indentation and will also use the same number of tabs as the surrounding code lines. If you want the new line to be less indented, you can press the BACKSPACE key one or more times to remove one or more Tabs.

CTRL-Right Click Navigation

Pressing CTRL+Right Mouse Button will open a right-click menu which allows you to jump to any specific event, UI item, function or rollout definition in the script. Selecting an entry from this menu will reposition the editor at the code line containing the definition of the selected item.

Bracket Balance

In complex scripts, it is common to lose track of blocks of commands, causing you to add extra parentheses or leave them out. You can find these errors by pressing CTRL+B. MAXScript will highlight the block that your cursor is on, showing you the start and end parentheses.

Color Coding

MAXScript in 3ds Max 5 and higher will display different elements of your script in different colors, making it easier for you to navigate your script at a glance. MAXScript will color-code your script in the following manner:

Comments - Green

Events (such as on, if, or while) - Blue

Text strings - Dark Red

The rest of the script remains black.

Automatic color coding will be performed when opening files and for the current line while typing in the Editor. It will not be performed in the Listener. To force an update of the color coding, press CTRL+D.

See also

The MAXScript Editor Windows

MAXScript Editor Commands

Next Topic

Controlling Program Flow in Scripts