I’m just optimizing my ways to keep my lua code short and sweet.
I’ve declared several images, and I actually have to hide many of them, right when the app starts.
So, I’ve wanted to throw them into a lua table and put them all as isVisible=false;
Here is what I’ve done so far:
local stats1 = display.newImage("stats1.png");
stats1.isVisible=false;
local stats2 = display.newImage("stats2.png");
stats2.isVisible=false;
local stats3 = display.newImage("stats3.png");
stats3.isVisible=false;
local stats4 = display.newImage("stats4.png");
stats4.isVisible=false;
local stats5 = display.newImage("stats5.png");
stats5.isVisible=false;
local stats6 = display.newImage("stats6.png");
stats6.isVisible=false;
local stats7 = display.newImage("stats7.png");
stats7.isVisible=false;
Eventually the stats images are actually going to be loaded from a json file.
So, I’d like to know if I do this:
statsImages = {"stats1","stats2","stats3","stats4", etc........}
--auto make the elements in statsImages table invisible
statsImages.isVisible = false;
The code above obviously doesn’t work. I’m certain i’ll need to loop through the table and perform something on each iteration. However, it doesn’t hurt to try asking if there’s an easier way, besides iterating.
If I were to do iterating, this is how I think I’d do it:
for i,v in ipairs(statsImages) do v.isVisible=false; end
And as luck would have it, that doesn’t work either.
So, any help would be appreaciated
[import]uid: 154122 topic_id: 27324 reply_id: 327324[/import]