Hi everyone !
I don't know much about coding and I have a little problem. I have several objects with the same name, just a different number (objet_1, object_2, object_3...etc) and I want to refer to one of them according to a string $i that equals the number of time the code is reapeting itself, like : object_($i) for object_3 when $i = 3. And if possible with a calcul like : object_($i+1) for object_5 when $i = 4. I just don't know the right syntax...
Is that posible ? If someone could help me it would be really great !
Thanks anyway !
Solved! Go to Solution.
Solved by saihtam. Go to Solution.
There is a couple of ways of doing this. Which approach you want to take depends on what you need your code to do. I'd recommend you do some more research on basic MEL. Check out this site. It's a horrible looking 90's website, but has a ton of excellent information.
Using a counting for loop with an array:
{ string $objects[] = `ls -tr "object_*"`; for($i=0;$i<size($objects);$i++) { string $currentObject = $objects[$i]; print "\n"; print $currentObject; } }
Using a counting for loop to construct strings:
{ for($i=0;$i<10;$i++) { string $currentObject = ("object_"+($i+1)); print "\n"; print $currentObject; } }
Using an object for loop:
{ string $objects[] = `ls -tr "object_*"`; for($object in $objects) { print "\n"; print $object; } }
Can't find what you're looking for? Ask the community or share your knowledge.