Notifications
Clear all

[Closed] Add an ID to an Array

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)
3 Replies

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: %
" myStruct.id
    format "myStruct.values: %
" 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: %
" (classOf testItem) )
  • Enrico

Hi Enrico,

Thanks a lot. ^^

But do you have an idea about my second question?

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