Hi, I said before I’m a beginner struggling on my first app which is a virtual pet kind of game.
Lately I’ve been trying to make it leak-free and I ran into one problem.
I have a global function gamescreen() for everything in-game.
Inside it there is a local updatePet() function which changes the state of the pet as the hunger changes.
At the end of the gameScreen function (if the pet dies) I call a destroyAll() function that removes and nils all display objects and also the main variables such as hunger (which is local to the gameScreen() function).
It looks kinda like this:
function gameScreen()
…
local function updatePet()
if hunger pet:changes…
elseif hunger<=0 then
end
end
timerUpdate = timerPerformWithDelay (1,updatePet,-1)
destroyAll()
function destroyAll()
timer.cancel(timerUpdate)
hunger=nil
…remove all…
end
end
And it actually does prevent almost all leaks (almost :))
The problem is while in the restart menu (after hunger = nil) it keeps spamming a mistake that in the line in updatePet() it tries to compare a nil to a number.
Why is the updatePet() function still running? I thought I ended it and also cancelled the timer… What did I forget?
Thanks!
[import]uid: 161390 topic_id: 29565 reply_id: 329565[/import]
