How would I reference them outside of the loop when it completes?
The dynamic variable names are what are primarily throwing me off, as I’m not sure how to implement those in Lua yet. [import]uid: 4621 topic_id: 1716 reply_id: 5039[/import]
The global namespace will be a slow way of accessing the display objects, include them in a group
Declare the group outside the loop
local imageGroup
for i = 1, 12 do
local newImage = display.newImage( "imageName.png" )
imageGroup:insert( newImage )
imageGroup.myImageName\_..i = newImage
end
Sorry I cant test this at the moment but I think it should work, you can access individual images like imageGroup.myImageName_5, you can also pass an array with a image name & file name and have it loop through the array taking the “image name” value for the imageGroup.myImageName and the file name to be passed to display.newImage() [import]uid: 5354 topic_id: 1716 reply_id: 5093[/import]
Many thanks, Matt! Very much appreciated.
I follow your logic and I think it’s a much better solution. [import]uid: 4621 topic_id: 1716 reply_id: 5136[/import]
I would like to thnks for your post. but i hv one query in your code,
How to append my loop variable with declared variable,
Like
local Myvar1 = “Hello”
local Myvar2 = “Testing for my first”
local Myvar3 = “Test This is my frist”
for i = 1, 3 do
– i append with my declared variable like Myvar+""+i
Myvari:setTextColor(0,0,0)
end
I hv try with like Myvar…""…i but not working…
@krunalbarot: is it ok with that, if i am use addEventListener on this arrya variable…?
Yes you can do that. I’m sorry you think tables (remember, in Lua there aren’t arrays, only tables) are complicated but Matt is correct, what you want is done with tables.
@cubbox: Matt already explained, you can’t append onto variable names like that. You can append onto strings, but variable names aren’t strings. As he pointed out, what you want is done with a table. [import]uid: 12108 topic_id: 1716 reply_id: 27229[/import]