[RESOLVED] How to create a random grid of colours

Hi there,

I am trying to make a random 4 x 5 grid of Red, Green and Blue squares. At the moment I can create a grid of all Red,Green or Blue squares but what I want is the grid to contain all the colours in a random pattern I know I am missing something really simple?

Here is my code:

[code]
local squares = {}
local idx = 0

local colorList = {{255, 0,0}, {0,255,0}, {0,0,255}}
local colorNames = {“red”, “yellow”, “green”}
local currentColor = math.random(1, #colorList)

function spawnSquares()
for y = 1, 5 do
for x = 1, 4 do
idx = idx + 1
local squares = display.newRect(0,0, 50,50)
squares.strokeWidth = 3
squares:setFillColor(unpack(colorList[currentColor]))
squares.x = (x * 75) - 23
squares.y = y * 70
squares[idx] = squares

end
end

end

spawnSquares()

[code] [import]uid: 167310 topic_id: 35911 reply_id: 335911[/import]

I think you need to call the

 currentColor = math.random(1, #colorList) 

inside the loop, otherwise all the rectangles will be the same color [import]uid: 128204 topic_id: 35911 reply_id: 142724[/import]

Thanks thassman that did it exactly what I was trying to achieve!!! [import]uid: 167310 topic_id: 35911 reply_id: 142726[/import]

I think you need to call the

 currentColor = math.random(1, #colorList) 

inside the loop, otherwise all the rectangles will be the same color [import]uid: 128204 topic_id: 35911 reply_id: 142724[/import]

Thanks thassman that did it exactly what I was trying to achieve!!! [import]uid: 167310 topic_id: 35911 reply_id: 142726[/import]

I think you need to call the

 currentColor = math.random(1, #colorList) 

inside the loop, otherwise all the rectangles will be the same color [import]uid: 128204 topic_id: 35911 reply_id: 142724[/import]

Thanks thassman that did it exactly what I was trying to achieve!!! [import]uid: 167310 topic_id: 35911 reply_id: 142726[/import]

I think you need to call the

 currentColor = math.random(1, #colorList) 

inside the loop, otherwise all the rectangles will be the same color [import]uid: 128204 topic_id: 35911 reply_id: 142724[/import]

Thanks thassman that did it exactly what I was trying to achieve!!! [import]uid: 167310 topic_id: 35911 reply_id: 142726[/import]