5x5 grid of rectangles using a for loop - storing them in a table so I can reference them?

Can anyone help me with this please, I did something similar last year using C#:

  
static int[,] HideCompSea = new int[5, 5]  
  
for (Row = 0; Row \< 5; Row++)  
 {  
 for (Col = 0; Col \< 5; Col++)  
 {  
 Console.Write("{0,-3}",GetShipChar(Sea[Col, Row]));   
 }  
  
 Console.WriteLine();  
 }  
  

The main idea of this is for a level select screen, I need 25 rectangles which I can click to trigger events, so I need to be able to define them in the table - has anyone done anything similar to this? [import]uid: 68741 topic_id: 14287 reply_id: 314287[/import]

I had this code lying around. Maybe it will help:
[lua]local cells = {}
local kLevelRows = 50
local kLevelCols = 50
local cellWidth = display.contentWidth / kLevelRows
local cellHeight = display.contentHeight / kLevelCols

– build screen now –
for x = 1, kLevelRows do
for y = 1, kLevelCols do
local cell = display.newRect((x-1)*cellWidth, (y-1)*cellHeight, cellWidth, cellHeight)
cell.strokeWidth = 1
cell:setStrokeColor(0,0,0)

if cells[x] == nil then
cells[x] = {}
end

cells[x][y] = cell
end
end[/lua] [import]uid: 19383 topic_id: 14287 reply_id: 52796[/import]

not sure what you are looking for excatly…
but if u just want 25 rectangles and an event triggered on each you may use the below code
[lua]local function tapRect(event)
print(“clicked rect:”…event.target.tag)
end

local i = 1
for row = 1,5 do
for col = 1,5 do
local rect = display.newRect(col * 30, row * 30,20,20)
rect.tag = i
i= i + 1
rect:addEventListener(“tap”,tapRect)

end
end [/lua] [import]uid: 71210 topic_id: 14287 reply_id: 52800[/import]