Hey guys
I'm trying to figure out the syntax for looping through actor name with a FOR loop.
I have - actor1, actor2 and actor3
I want to set some properties, like …
actor1.hungry = false;
actor1:setY(100)
etc.
I don't want to do this over and over for each actor as the properties will be the same every time.
Is there a way I can do something like this?
for i = 1, 3 do
(actor+"i").hungry = false;
(actor+"i"):setY(100)
end
Thanks in advance for any help
Comments
I'm still wondering (just out of interest) whether there is a way to do something similar to this … (actor+"i"):setY(100) … without using an array?
The reason I ask, is that I do something similar in AS3 to access instance names.
example as3 code … (my actors on the stage are name actor1, actor2 …)
for (i=0; i<4; i++) { this["actor"+i].buttonMode = true; }
actor.."1":setY(100)
actor.."2":setY(100)
actor.."3":setY(100)
actor.."4":setY(100)
on the other hand if actor1 has been declared as local, is there a way to access it?
_L["actor"..i]?
But not that easy.
There is a function: debug.getlocal(level, local)
where level is the number - amount of functions or scopes deep from global scope, and local, is the index (order) when the variable was created
and it returns variable name and value
More info: http://pgl.yoyo.org/luai/i/debug.getlocal
like:
table: 068B5340
nil
actor1 table: 068B5340
But as you might guess, it should be only used for debugging/profiling and not in the release versions, as it is probably slow as hell
So, arrays are the only way to do this efficiently?
My dream solution sure looked sexier
Likes: ar2rsawseen