Notifications
Clear all

[Closed] How to define variable based on an array?

I am wondering is it possible to convert an array of strings to variable respectly? For example,

theArray = #(“a”,“b”,“c”)

how can I convert theArray[1] to a variable with a name of “a”? Another question is how can I filter variable names just like strings? Convert variable names to string?

Thanks for the help!

6 Replies

deleted thanks gravey

In short: No.
Sorry it’s just not possible since maxscript only really ‘sees’ the value stored in a variable and doesn’t care what we have named it

sigh… I got it, thanks!

Perhaps you could post your actual problem, so we can suggest an alternative on how to solve it.

Regarding the first question, you can turn an array of strings into variable names like this:


for varName in theArray do ( 
   execute (varName + " = 1")
)

The above sets all the new variables to a value of 1. Change that part as needed, I don’t know what values you were after.

Second question, I don’t think there’s a strightforward way to do this in MaxScript. It’s not the most introspective language on the block. But this should work:


theVariable = 1 
refString = &theVariable as string
splitString = filterString refString ":"
varName = splitString[2]

… that is, if I understood the question correctly.

Thanks Adam, that’s exactly what I am looking for. I’ve figured out a way to solve the prblem at hand based on your method, thanks a lot!!