PDA

View Full Version : Add an ID to an Array


holycause
04-13-2009, 11:22 AM
I m back with a new silly question.

I was wondering if it is possible to add some custom IDs to an Array and to a Variable as well

so i could control a radioButton state.

ie:

ArrID = MyArray.id
MyRollout.Rdo.state = ArrId

edit: or is there a way to know if a variable is an array or just a simple variable

how could ms knows that the first one is a simple variable and the second one, an array

Test01 = "Variable"
Test02 = #("Variable",pi,$Sphere01.radius)

SyncViewS
04-13-2009, 12:01 PM
Hi Ruben,
variables as well as arrays don't have an "ID" property. You can anyway achieve a similar result by definining a custom structure containing an id variable and a regular array, then access them with the dot synthax.

(
struct Holder (
id,
values = #()
)

myStruct = Holder()

myStruct.id = "theID"
for i = 1 to 3 do ( myStruct.values[i] = i*10 )

format "myStruct.id: %\n" myStruct.id
format "myStruct.values: %\n" myStruct.values
)


MaxScript is a loosely typed language, that means variables are placeholders for any kind of object, being it a value or a structured type. You can query the stored type with "classOf".

function typeTest testItem = ( format "variable type: %\n" (classOf testItem) )
- Enrico

holycause
04-13-2009, 12:13 PM
Hi Enrico,

Thanks a lot. ^^

But do you have an idea about my second question?

SyncViewS
04-13-2009, 12:42 PM
edit: or is there a way to know if a variable is an array or just a simple variable
how could ms knows that the first one is a simple variable and the second one, an array

Test01 = "Variable"
Test02 = #("Variable",pi,$Sphere01.radius)

Well, you can test it by:
if ((classOf testItem) == Array) then ( ... )
If 'testItem' is an Array code is executed, if otherwise it is anything else (a Float, a String, a Camera, a Geopetry Object, ...) code is skipped.

- Enrico

CGTalk Moderation
04-13-2009, 12:42 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.