issue double cycle for

hi…

I contact because i’ve a problem with a table in a double cycle for. 

I created a table with 10 images and i tried to show those images trought a double cycle for. The problem is that the code repeat only the first 5 images. 

Anyone can help me to solve this problem ?

Here the code

local button = {} local object = {} object[1] = {img = "shot.png"} object[2] = {img = "key.jpg"} object[3] = {img = "key.jpg"} object[4] = {img = "shot.png"} object[5] = {img = "shot.png"} object[6] = {img = "key.jpg"} object[7] = {img = "key.jpg"} object[8] = {img = "key.jpg"} object[9] = {img = "key.jpg"} object[10] = {img = "key.jpg"} for i = 1,5 do for a = 1,2 do button[i] = display.newImageRect( object[i].img,45,40 ) button[i].anchorX = 0.5 button[i].x = i \* 50 button[i].y = 100 + a \* 50 end end

what of you cajnge it to 1,10?

i tried to insert 1,10 in the first cycle for (horizontal line). It show the complete table in horizontal, but in the second line it repeat the flirt line. I need 2 lines with every images not replaced.

I think what you’re going for, is more like the below:

button[#button+1] = display.newImageRect( object[#button+1].img,45,40 ) button[#button].anchorX = 0.5 button[#button].x = i \* 50 button[#button].y = 100 + a \* 50 print(#button)

There are more efficient ways of accomplishing what you’re going for, but this should get you where you want to go, for the time being.

Now i understand my error. 

thanks to help me…

what of you cajnge it to 1,10?

i tried to insert 1,10 in the first cycle for (horizontal line). It show the complete table in horizontal, but in the second line it repeat the flirt line. I need 2 lines with every images not replaced.

I think what you’re going for, is more like the below:

button[#button+1] = display.newImageRect( object[#button+1].img,45,40 ) button[#button].anchorX = 0.5 button[#button].x = i \* 50 button[#button].y = 100 + a \* 50 print(#button)

There are more efficient ways of accomplishing what you’re going for, but this should get you where you want to go, for the time being.

Now i understand my error. 

thanks to help me…