Create and fill a grid in Lua/Corona

Hello everyone I am trying to setup a grid of 12x9 for iPhone and 17x13 for iPad in the same code and fill it up randomly with a specific number of type of items (2,3,4 or more types) and also allow user to choose how many types to display on screen prior to filling. Could anyone give me a hand with the code this is my first in Lua & Corona for me, any help is appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
-- cache our math function
local rnd=math.random
 
-- somewhere to add our items too
local board = display.newGroup()
 
local itemsAcross
local itemsDown
 
-- 4 item types here
local images = 
{
  "red.png",
  "blue.png",
  "green.png",
  "yellow.png" 
}
 
-- this is the known width/height of our image for instance
local itemWidth=32
local itemHeight=32
 
-- size of grid
-- you might check for iPhone/iPad here to change this
itemsAcross = 12
itemsDown = 9
 
-- start at row 1 and work down
for y=1, itemsDown, 1 do
 
  -- start at column 1 and work across
  for x = 1, itemsAcross, 1 do
    
    -- pick a random number between 1 and number of images
    local r = rnd(1,#images)
    
    -- add image "r" from the array
    local img = display.newImage(images[r])
 
    -- plot the image on the grid
    img.x = (x-1) * itemWidth
    img.y = (y-1) * itemHeight
 
    -- add it to our group
    board:insert(img)
  end
end

thanks jmp909 this was very helpful, either line 25 or 26 should be "itemsDown". The images do appear on screen but go over the edges
is there a way to design this and the whole app so that depending on the iDevice it's running on it creates the right size grid and number of items, images dimensions are 65x65 pixels.

yes that's why i made variables that you can change in an if statement that checks the system info
http://developer.anscamobile.com/reference/index/systemgetinfo

views:1678 update:2011/10/6 9:28:12
corona forums © 2003-2011