Structs
MaxScript allows you to create structs with functions. Essentially this means you can write object oriented code if you wish to do so. Structs in many ways are similar to how they would work in C++.
Syntax
struct <struct name> (
<data member1>,
<data member2>,
...
<last data member>,
fn <memberfunction1> <memberfunction parameters> = (
<member function definition>
),
fn <memberfunction2> <memberfunction parameters> = (
<member function definition>
),
...
fn <lastmemberfunction> <memberfunction parameters> = (
<member function definition>
)
)
A few syntactic quirks. All members are comma separated. So once you start a struct, everything member you create in that struct is separated by every other member with a comma.
All data members can be initialized using = operator to specify default values. Data member values can be supplied using either their order or their names. When using names, you can use any ordering.
members can be accessed using (.) notation as with C++
struct myObject (
a = 8,
b = 3,
fn doAdd = ( return a+b),
fn doDiv = (return a/b)
)
fn myMain = (
one = myObject()
two = myObject 6 5
three= myObject b:5 a:20
print (one.doDiv())
print (two.doDiv())
print(three.doDiv())
)
myMain()
Starting with max 2010, you are allowed to create public vs private members and their function is similar to C++. in earlier versions of max, all members are public.