Posted more or less the same question in another thread with some more details, but hopefully this one’s less convoluted 
How can I reference an object within a for loop using the count as part of the objects reference?
For simplicities sake, let’s say I have 2 images on screen:
local image1 = display.newImage( “firstimage.png”, 0, 0)
local image2 = display.newImage( “secondimage.png”, 0, 0)
If I want to use a for loop to access both images - what’s the proper syntax to reference them, using the “image” prefix + the “i” count?
Something like…
for i = 1, 2, 1 do
tryingtoaccess = “image” … i
print(tryingtoaccess)
end
…outputs the right string when printing it - but I can’t actually seem to reference an object with that strings name. When I try, I get the error:
"attempt to index global ‘i’ (a string value)"
I’d be using this to move multiple existing images within that for loop, and had hoped something like this would work:
for i = 1, 2, 1 do
tryingtoaccess = “image” … i
tryingtoaccess.y = 200
end
(which would move both image1 and image2 to that y co-ordinate accordingly.)
Any help much appreciated!