Hello
I am learning a lot about loops, thanks to all of you.
I using this post, for future reference and for anyone like me
really new to loops.
a basic loop with a “touch” function
local number = 1 for i = 1, 7 do nail[i] = display.newImageRect( sceneGroup, "images/nail" .. number .. ".png", 250, 188 ) nail[i].x = display.contentCenterX nail[i].y = display.contentCenterY + i\*120 nail[i]:scale (.6, .6) nail[i].isVisible = true nail[i].name = i nail[i].touch = touch nail[i]:addEventListener("touch") number = number + 1 end
I got this from this post. However, in this loop I have a different image each time
because of the – … number … – I think is “concatenation”
so I got nail1, nail2, nail3 and so on
but if I want to get diferent numbers and add a condicional “if” like this
if ar.data.note == true then p1 = display.newImageRect ( sceneGroup, "images/n40.jpg", 106, 106) end if ar.data.note == false then p1 = display.newImageRect ( sceneGroup, "images/a40.jpg", 106, 106) end
Notice that one is " n40" and the other one is “a40”
I have a list of 88 numbers, n52, n47, n08 like that
so far i do this 60 times
if archivo.datos.doremi == true then p13 = display.newImageRect ( sceneGroup, "images/n45.jpg", 106, 106) end if archivo.datos.doremi == false then p13 = display.newImageRect ( sceneGroup, "images/a45.jpg", 106, 106) end p13.x = pin2[5].x p13.y = pin2[5].y p13:scale (1.2, 1.2)
it’s a lot!
QUESTION
If I have 60 “p” variables – p1, p2, p3, p4 …
each of them has a different image n52 or a52, n47 or a47 like that
and also different .x and .y position
How would I do that in a loop for i = 1, 60 do ?
I hope you understand my question thanks.