Set up multiple display objects in a loop

Hello,

how can i set up (for example) a playing field of 4 * 3 fields in one loop?

I mean, i don’t want to write 12 times:

local field_01 = display.newRect(x + 10, y, 32, 32)

local field_02 = display.newRect(x + 20, y, 32, 32)

local field_03 = display.newRect(x + 30, y, 32, 32)

.

.

.

I see some solution with tables in the starting guide, but the example there is not shown completly and

has some errors inside.

Thx for all upcoming help.

greetings

Make a for loop!

local x = 10 local field = display.newGroup() for i = 1, 12 do local object = display.newRect(x+10, y, 32, 32) x = x + 10 -- 2nd time through, x will be 20! field:insert(object) -- now objects are object[1], object[2], etc. end

Wow, thanks for this fast response!  I will try this :slight_smile:

Make a for loop!

local x = 10 local field = display.newGroup() for i = 1, 12 do local object = display.newRect(x+10, y, 32, 32) x = x + 10 -- 2nd time through, x will be 20! field:insert(object) -- now objects are object[1], object[2], etc. end

Wow, thanks for this fast response!  I will try this :slight_smile: