MAXScript Language Reference > Structure Definition >

# Structure Scope While Initializing

When initializing a structure, the scope will be set to the structure's context. Note that this effectively lets you run a function within the structure when an instance of the structure is created!

For example, when creating an instance of the following structure, the variable 'foo' is initialized to 2, the function 'onCreate' increments the value of foo and then returns a value of foo plus 3, and the variable 'a' is initialized to the result of calling the function 'onCreate':

EXAMPLE:
    struct doinStuff (
    foo = 2,
    fn onCreate= (foo += 1;foo+3),
    a = onCreate()
    )
    DoIt = doinStuff()
RESULTS IN:
    doinStuff foo:3 a:6

You can be real inventive with what you can do when you create a structure instance.

#### See Also

- Structure Definition

- Defining Local Functions in Structures

- Structure Inherited Methods

- Structure Creation and Cloning Event Handlers

- Private and Public Members in Structure Definitions