Timer Not Being Created Again After Pausing

I have a pause button that works well until after I unpause the game. I have a timer that is supposed to be created again (I can’t pause them as a trial user), but it isn’t doing that.

Error to prove it’s not being created:

Windows simulator build date: Dec 9 2011 @ 14:01:29 Copyright (C) 2009-2011 A n s c a , I n c . Version: 2.0.0 Build: 2011.704 Paused Unpaused Paused Runtime error ?:0: attempt to index a nil value stack traceback: [C]: ? ?: in function 'cancel' ...le\documents\my code\corona sdk\makin' bank\game.lua:109: in function <...le code sdk bank><br> ?: in function <?:21 <br>Memory Usage: 0.132326171875 MB<br>Texture Usage: 8.912896<br>

Code:
[lua] local function pauseGame()
isPaused = not isPaused
if isPaused then
buttonPause:prepare(“pauset”)
buttonPause:play(“pauset”)
physics.pause()
buttonLeft:removeEventListener(“touch”, moveLeft)
buttonRight:removeEventListener(“touch”, moveRight)
Runtime:removeEventListener(“enterFrame”, moveCharacter)
Runtime:removeEventListener(“touch”, stopCharacter)
timer.cancel(createCoinsTimer) – Change to Pause
else
buttonPause:prepare(“pauseu”)
buttonPause:play(“pauseu”)
physics.start()
buttonLeft:addEventListener(“touch”, moveLeft)
buttonRight:addEventListener(“touch”, moveRight)
Runtime:addEventListener(“enterFrame”, moveCharacter)
Runtime:addEventListener(“touch”, stopCharacter)
createCoinsTimer = timer.performWithDelay(500, createCoins, 0) – Change to Resume
end
end[/lua]

I have another question, and I might as well get it answered here: Do I need to remove local objects/timers in my exitScene and destroyScene functions, or are they automatically removed? I’m confused on what is removed automatically and what isn’t. Also, if I have a global object that is in the local group, is that removed automatically? [import]uid: 103624 topic_id: 19300 reply_id: 319300[/import] </…le>

If you download build 704 I believe you should be able to pause them just fine. (704 is the latest stable build and available to test users.)

Peach :slight_smile: [import]uid: 52491 topic_id: 19300 reply_id: 74495[/import]

Thanks. I have one more question, though.

In my enterScene, my timer is created. In exitScene, it’s paused. In destroyScene, it’s canceled.

My question is, will I run into a similar problem as before because every time the player re-enters the game screen it will try and create a timer and fail? [import]uid: 103624 topic_id: 19300 reply_id: 74699[/import]

Bump [import]uid: 103624 topic_id: 19300 reply_id: 74824[/import]

Every time you bump a thread I’ve been in, I get an email notification. I got one when you posted the first time, bumping so soon just gives me more emails to dig through - so please, no more needless bumps :wink:

You can avoid issues by checking if the timer exists when you enter the scene again. If it does you can resume it if it doesn’t you can create it. That should work fine.

Peach :slight_smile: [import]uid: 52491 topic_id: 19300 reply_id: 74831[/import]