So I’m working on what’s basically an assignment for college course and I’ve been wracking my brain trying to figure out how to solve the problem. I have a 2D array that contains nine objects which in turn hold 14 objects (is array the right term?) a grid is generated of this size (9 across, 14 down) of squares. When a grid is tapped, the colour is supposed to change. The issue I’m having is I can’t figure how to get it such that the :setFillColor works in the function without it coming up as a nil value. If someone could point me in the right direction, that’d be swell.
function tappedRect(x) print("tapped") -- Testing function x:setFillColor (0, 255, 0) -- unsure what to type here to get the color to change. end for i = 1, gridWidth, 1 do grid[i] = {} for j = 1, gridHeight, 1 do grid[i][j] = {} end end for i = 1, gridWidth, 1 do for j = 1, gridHeight, 1 do grid[i][j].ship = false xCoOrd = i \* 60 -- The squares are fifty pixels wide. This creates the grid with 10 pixels gap across yCoOrd = j \* 60 -- The squares are fifty. This creates the grid with 10 pixels gap down. grid[i][j].squares = display.newRect(xCoOrd, yCoOrd, 50, 50) -- grid[i][j].squares saves the memory of the squares grid[i][j].squares:setFillColor(255,255,255) grid[i][j].squares:addEventListener("tap", tappedRect) end end