[Resolved] for loop with images.. help

I need help with for loops:

So your standard for loop is this:
for i = 1 , 5 do
print( "Hello, "…i )
end

But that just prints a sequence in the terminal.

How do I merge the above code with:
local BirdY_1 = display.newImageRect( “BirdY1S.png”, 120, 120 )
BirdY_1.x = 300
BirdY_1.y = 310

So that the same image gets displayed 5 times. Logic would also say you would need to write a position equation so images don’t get stacked on top of themselves.
Thanks.
Jeremy
[import]uid: 127028 topic_id: 27277 reply_id: 327277[/import]

Do this:
[lua]counter = 0
for i=1,5 do
counter = counter + 20
local BirdY_1 = display.newImageRect( “BirdY1S.png”, 120, 120 )
BirdY_1.x = counter
BirdY_1.y = 310
end[/lua]

Hope this helps!

Regards,
Jordan Schuetz
Ninja Pig Studios [import]uid: 29181 topic_id: 27277 reply_id: 110901[/import]

Here is another way to do it:

  
local x\_offset = 0  
for i = 1 , 5 do  
 local BirdY\_1 = display.newImageRect( "BirdY1S.png", 120, 120 )  
 BirdY\_1.x = 300 + x\_offset  
 BirdY\_1.y = 310  
 x\_offset = x\_offset + 60  
end  

You can do the same for y. Just change the 60 to fit your need. If you want unique variables for each image, you can put them in a table by using

local BirdY[i] = display.newImageRect( "BirdY1S.png", 120, 120 ) [import]uid: 129287 topic_id: 27277 reply_id: 110903[/import]