Source Code Layout

The layout rules for MAXScript code are unlike those of most programming languages. MAXScript gives you the advantage of freeform languages, such as C and C++, without the need for extensive punctuation.

MAXScript lets you break statements and expressions across lines wherever you want. The line break can be in the middle of an expression. MAXScript reads your code until the end of each line and determines whether it has a complete expression. If it does not, it continues to read subsequent lines until it finds the rest of the expression.

Take as an example the following line:

a + b * c / d - e + f * g / h

This line can be broken after any of the operators. MAXScript continues to read the next line, because an operator needs another argument.

For example:

a + b * c / d - e +

f * g / h

You cannot break the example line as shown next and get the same result, because the expression on the first line is a complete expression. MAXScript considers the two lines as separate expressions, and the second line is now syntactically wrong, because it starts with an operator:

Wrong syntax:

a + b * c / d - e

+ f * g / h

If you do want to break a line at the end of a sub-expression, you can use the backslash line continuation character: ‘\’. The previous example of an invalid break can be made valid using the line continuation character after the ‘e’:

For example

a + b * c / d - e \

+ f * g / h

Whenever MAXScript encounters a ‘\’ as the last character on a line (except for spaces, tabs, or comments), it continues to read the next line as though the break were not present. Line continuations can be useful for breaking up long or complex lines of code, making them easier to read.

MAXScript also lets you combine multiple statements and expressions in a single line. The statements or expressions are separated with a ‘;’, for example:


Sometimes it is useful to enter comments within your script to provide guidance or context. You can enter comments in MAXScript by preceding your comment with a double-hyphen (‘--‘). As soon as MAXScript reaches the double-hyphen, it stops evaluating the rest of that line.

For example:


Next Topic

Entering Information into MAXScript