GENERATE/PREV.gifGENERATE/NEXT.gif

Local Variables and Scoping

To further assist the structuring of code, MAXScript lets you declare local variables in a block-expression. These are typically used to hold temporary or intermediate results that may be dropped when the block is exited. You declare local variables in a block with the <local_decl> construct, introduced in the topic Variables, Assignment and Scoping. Here is the syntax again:

local <decl> { , <decl> }

where <decl> is defined as:

<name> [ = <expr> ]      -- optional initial value

Example:

local foo

local x = 0, y = 100

You use local variables in block expressions like this:

(

local foo = $box01.pos

print foo.x

local baz = length foo

$box02.pos.x += baz / 2

baz      -- value in baz is block result

)

You can use local declarations at any point in the expression sequence. They are usable from there on in the block.

See also:

Scoping and Extent