Including Scripts Within Scripts

MAXScript provides a compile-time source-file include mechanism, allowing you to break up large scripts into smaller files that can be included at nearly any point in a script. You can use the include <file> construct at any point in your code to effectively insert the contents of a file at that point in your code.

The form is:

include "filename_string"

 

This is a compile-time construct, therefore the file name specification must be a string literal, and not a variable or an expression.

Example:

utility foo "Baz"

(

local a, b, c

include "foo-ui.ms"

rollout bar "Bar"

(

include "bar-rollout.ms"

)

include "foo-handlers.ms"

)

The include <file> construct is effectively replaced in the source code at that point with the contents of the named file.

You can nest included files as deeply as needed; included files can include other files, and so on.

Because include is a compile-time construct, the current MAXScript scope is maintained within the included file. This is opposed to the fileIn() method described in Running Scripts, whose script file content is compiled in a global scope context. For more information, see Scope_of_Variables.

The include <file> can appear at any point a new token is expected, such as a name, literal, or punctuation. This means that you could complete a partial expression with an included file. For example:

include "op1.ms" + include "op2.ms"

if include "test2.ms" then print a else print b

You cannot place an include <file> within a token. For example, the following is not valid:

timeval = 2:include "framenum.ms".0