Source Code Layout and Continuation Lines

The layout rules for MAXScript code are unlike those of most programming languages and give you the advantages of freeform languages, such as C and C++, but without the need for extensive punctuation, like semicolons and parenthesized parameter lists.

MAXScript lets you break statements and expressions across lines wherever you want, providing the line break is 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.

NOT POSSIBLE:

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 above of an invalid break can be made valid using the line continuation character after the 'e':

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 line break were not present.

Line continuations are often used to break up function calls with many arguments, as shown in many of the Expressions topics.

This scheme allows you to write the following forms of the same statement without using periods or semicolons, as you might in other freeform languages.

FOR EXAMPLE

An if/then/else construct could be written as:

if a < b then print c else print d

or

if a < b then print c
else print d

or

if
a < b
then
print c
else
print d

MAXScript also lets you combine multiple statements and expressions in a single line. The statements or expressions are separated with a ';'.

EXAMPLE

print "End of input data reached" to:f ; close f ; f = undefined
if a < 0 do (print "value out of range";a=0)

Comments in MAXScript begin with a double-hyphen ('--') and extend to the end of the current line. Many code examples in this help file use comments in this style.

EXAMPLE

-- special cases...
if first do
subanims[6]=undefined-- subanims[6] is #Image_Motion_Blur_Multiplier