MAXScript has two kinds of variables, global and local. Global variables are visible in all running MAXScript code and hold their values until you exit MAX. Local variables are visible to code only in the function or block-expression in which they are declared, and hold their values only as long as the current function or block is executing. This is similar to how most modern programming languages implement variables. Variables are identified with MAXScript >SP<names>, as described in the Names topic.
You don’t need to explicitly declare variables before you can use them. MAXScript creates an undeclared variable the first time you use it, and initializes it to hold the special value undefined. It defines implicitly declared variables as local if you use them for the first time inside a function or block, or as global otherwise. There are language constructs that let you explicitly declare and initialize both kinds of variables and it is good practice to use these to be sure what kind of variable you have.
The syntax for variable declaration, <variable_decls>, is as follows:
( local | global ) <decl> { , <decl> }
where <decl> is defined as:
<name> [ = <expr> ] -- name and optional initial value
A local or global declaration can have one or more comma-separated variable declarations and each one can have an optional initial value assigned. The <expr> construct is a general MAXScript expression defined in the Expressions topic.
global baz -- initialized to 'undefined'
global foo, bar
local x = 1, -- continued on several lines
y = 2,
z = sqrt(123.7)
For more information, see the following topics: