Notifications
Clear all

[Closed] Combining variable names

Hi,

How can I combine variable names in max?

For example: varName+i

Like with strings: “String”+i

8 Replies
 j83

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

I’m looking for something similar and they directed me to here but I haven’t any chance on getting how it works.
Hope you get it!

1 Reply
(@starsybil)
Joined: 10 months ago

Posts: 0

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)

 j83

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()"
  )
  
  
 lo1

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)