Hi so I have a function that adds rectangles in a grid
function draw\_background() for y = 9, -300, -1 do for x = 7, 0, -1 do backX = x backY = y createX = (x \* rectWidth) - 50 createY = (y \* rectHeight) - 72 local rect = display.newRect(createX, createY, rectWidth, rectHeight) rect:setFillColor(0.5) rect.name = (x .. y) mapGroup:insert(rect) end end generate\_moves() end
and I do some calculations to figure out what rectangles I need to remove from the objectGroup. I already have the calculation and detection part working to know what rectangle to remove. I am just stuck with the error attempt to index field ‘?’ (a nil value) from trying mapGroup:remove(d) in this code
function make\_tile(x, y) --function to spawn the tile on the playboard if x \< 1 then --if the tile too far left then spawn it as far left x = 1 elseif x \> 7 then --if the tile is too far right the spawn it as far right x = 7 end tileX = (x \* rectWidth) - 50 --calculations to make the screen a 7x9 tile board with rectangles fitting tileY = (y \* rectHeight) - 72 --rect = display.newRect(tileX, tileY, rectWidth, rectHeight) for d = 1, mapGroup.numChildren do thisTile = mapGroup[d].name if thisTile == x .. "" .. y then mapGroup:remove(d) \<---------------- I get the error from this end end end
Thank you if you can help me out.