[Closed] Combining variable names
Hi,
How can I combine variable names in max?
For example: varName+i
Like with strings: “String”+i
Do you mean something like this?
(
local myString = "Hi "
local myString2 = "there."
myString += myString2
local myInt = 1
local myInt2 = 4
myInt += myInt2
)
No,
I want to combine a variable name with another variable name into a new variable name.
I go through a for loop and in every loop i create a cylinder.
I want i to be added to the variable name of that cylinder for every increment.
So I would end up with (for i = 1 to 100:) cylinder1, cylinder2, … cylinder100 as variable names
Just tried it really quick:
for i=1 to 20 do
(
execute("Cylinder_"+(i as String) + "= cylinder()" )
execute("print " + "Cylinder_" + i as String)
)
Works like a charm
Edit: Just noticed that j83 already posted almost the same thing before me. My bad.
you mean object names, not variable names?
cylinder.name=“cylinder” + (i as string)
Not sure why you would structure it this way, it would be really slow, but here is an example of combining the iterator into a variable.
(
for j = 1 to 50 do
(
execute (("myBox" + j as string) + " = Box pos: [random -100 100, random -100 100, random 0 50]")
)
execute "completeRedraw()"
)
While this can be done the way j83 showed, there’s really no reason you’d ever need to do something like this.
consider using an array instead
objs = #()
for i = 1 to 10 do objs[i] = whatever
Better than using Execute, you can also use:
Getnodebyname (“String” + i as string)