PDA

View Full Version : structs - lost properties


TheGrak
07-05-2011, 10:06 PM
I guess I suffer from a naive understanding of structs.
Please look at this and verify that I'm not going insane:


(
struct person (name, height, age, sex)
bill = person name: "Bill" height:72 age:34 sex:#male
--joe = person name: "Joseph" sex:#male --uncomment this line to make it work
joe = person --uncomment this line to break it

bill.age --returns 34
joe.age --Unknown property: "age" in #Struct:person

--Since the height and age members are not assigned values, and do not have
--optional initial values supplied in the structure definition, they default to
--a value of undefined.

--* a struct instance must be constructed with at least one property defined
--otherwise, the struct instance doesn't have access to it's properties
)


The important bit is this: "a struct instance must be constructed with at least one property defined, otherwise the struct instance doesn't have access to it's properties".
Is this an accurate statement?
Would the above snippet work if the struct properties were initialized to some value?

Thanks, I'm trying to get a better understanding of how structs work in maxscript.

TheGrak
07-05-2011, 10:23 PM
actually, i was just missing the () after person. d'oh! :(

denisT
07-05-2011, 10:28 PM
I guess I suffer from a naive understanding of structs.
Please look at this and verify that I'm not going insane:


(
struct person (name, height, age, sex)
bill = person name: "Bill" height:72 age:34 sex:#male
--joe = person name: "Joseph" sex:#male --uncomment this line to make it work
joe = person() --uncomment this line to break it

bill.age --returns 34
joe.age --Unknown property: "age" in #Struct:person

--Since the height and age members are not assigned values, and do not have
--optional initial values supplied in the structure definition, they default to
--a value of undefined.

--* a struct instance must be constructed with at least one property defined
--otherwise, the struct instance doesn't have access to it's properties
)




you forgot to set brackets...

EDIT: you are too quick. or I'm too slow... already fixed.

CGTalk Moderation
07-05-2011, 10:28 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.