PDA

View Full Version : How to define variable based on an array?


Avatarye
12-24-2007, 03:35 AM
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!

MoonDoggie
12-24-2007, 09:16 AM
deleted thanks gravey

Gravey
12-24-2007, 10:16 AM
Another question is how can I filter variable names just like strings? Convert variable names to string? 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

Avatarye
12-25-2007, 02:22 AM
sigh... I got it, thanks!

scorpion007
12-25-2007, 03:29 AM
Perhaps you could post your actual problem, so we can suggest an alternative on how to solve it.

vScourge
12-25-2007, 02:33 PM
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.

Avatarye
12-26-2007, 02:18 AM
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!!:)

CGTalk Moderation
12-26-2007, 02:18 AM
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.