I'm having problems with clearing the data in a LUA table. I use the Scene plugin and as soon as the player advances to the next scene, then I'd like to reset the data in a table.
I use this function to create the game elements:
local function createGrips()
local originX = 0
local originY = height -75
for i=0,numberGrips do
r = math.random(3)
local x = originX + math.random(width)
local y = originY - math.random(2*height)
grip[i] = display.newRect(allElements, x, y, gripSize[r].w, gripSize[r].h)
grip[i].status = "active"
grip[i].size = gripSize[r].s
if (r == 1) then
grip[i]:setFillColor(51,255,0)
elseif (r == 2) then
grip[i]:setFillColor(255,51,51)
elseif (r == 3) then
grip[i]:setFillColor(51,51,255)
end
end
end
createGrips()
As I move to the next scene I have tried all these options to clear the table:
grip={}
or this one
for i=#grip,0, -1 do
table.remove(grip,i)
end
but the result stays the same. The elements keep staying on the screen. The only thing that was working was grip=nil. But this then created an error, as soon as I returned to the function createGrips().
What would be the best way to reset all the data? I'm using the removeSelf() function for all the characters.