Learning MAXScript > Creating Your Own Scripts >

# Structure Definitions

In addition to custom functions, you can also create custom compound values in MAXScript using "structure definitions". Structure definitions are a flexible data type, built of simpler data types. They let you define the layout of a new structured type of value that you can then create and work with in your code.

The syntax for a structure definition is:

    struct <struct_name> ( <member> , <member> )

where each <member> can be one of:

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

Create a new structure, called person:

    Struct person (name, height, age, sex)

Now create an instance of this structure using the ‘person’ constructor:

    Bill = person name:"Bill" height:72 age:34 sex:#male

This stores an instance of the person structure in the variable Bill. Member name is initialized to the string value "Bill", height to the integer value 72, age to the integer value 34, and sex to the name value #male. Create another instance:

    Joe = person name:"Joseph" sex:#male

In this example, another ‘person’ is created. However, this person does not have initialized values for the height and age members. Since you did not provide these members with an optional default value in our structure definition, they will default to a value of undefined.

Structure definitions are a good alternative to arrays when you have a fixed, small number of components. The code for these types of values is easier to work with since you can reference property names rather than index numbers in arrays.

Next Topic

3ds Max Commands in MAXScript