Reusing timers or using multiple timers

I have a intermediary screen between rounds in my game, which counts down from 10 before advancing to the next scene. I want to allow the user to pause and resume here. The first time I reach this screen it works fine. Here is the code for it, the next time I use this screen and try to pause the timer I get this:

WARNING: timer.resume(timerID) ignored b/c timerID was not paused, what am I doing wrong

local storyboard = require( "storyboard" )  
storyboard.removeAll()  
storyboard.purgeOnSceneChange = true  
local scene = storyboard.newScene()  
  
---------------------------------------------------------------------------------  
-- BEGINNING OF YOUR IMPLEMENTATION  
---------------------------------------------------------------------------------  
  
local image, image2  
local gameIsActive = true;  
local paused = false;  
  
total = storyboard.num11 + storyboard.num10  
  
-- Called when the scene's view does not exist:  
function scene:createScene( event )  
 local widget = require( "widget" )  
 require("ice")  
 local scores = ice:loadBox("scores")  
 image = display.newImage( "images/Background(640x480).png", -20 ,0 )  
  
 text = display.newText("Round Complete - You won Coins ", 45, 80, "comic sans ms", 22)  
 text:setTextColor(255,250,250)  
 text4 = display.newText(storyboard.num11, 320, 80, "comic sans ms", 22)  
 text4:setTextColor( 0, 206, 209)  
  
 text2 = display.newText( " number of coins won so far is ", 100, 130, "comic sans ms", 22)  
 text2:setTextColor(255, 250,250)  
 text2 = display.newText( "Total", 45, 130, "comic sans ms", 22)  
 text2:setTextColor(255, 0,0)  
  
 text5 = display.newText(total, 420, 130, "comic sans ms", 22)  
 text5:setTextColor( 0, 206, 209)  
  
 text3 = display.newText( "Good Luck in Round 3, Starting in... ", 45, 180, "comic sans ms", 22)  
 text3:setTextColor(255, 250, 250)  
 print( "\n2: createScene event" )  
  
 local player1 = display.newRect( 0, 0, 0, 0 )  
 player1.text = display.newText("Coins: ", 10, 16, "comic sans ms", 20)  
 player1.score = display.newText( "0", 90, 16, "comic sans ms", 20)  
 player1.score:setTextColor(255,215,0)  
 player1.score.text = scores:retrieve("player1") or 0  
  
 local resumeBtn = display.newImage("pause\_button.png");  
 resumeBtn.x = 440;  
 resumeBtn.y = 40;  
 local pauseBtn = display.newImage("play\_button.png");  
 pauseBtn.x = 440;  
 pauseBtn.y = 40;  
  
 pauseBtn.alpha = 0  
 resumeBtn.alpha = 1  
  
  
local countDown = 10  
pauseTime = false;  
resumeTime = true;  
   
local timerText = display.newText( "", 420, 197, "comic sans ms", 22)  
timerText:setTextColor( 255, 255, 255 )  
   
local timeBut = display.newRect( 50, 50, 100, 50 );  
timeBut.x = 440;  
timeBut.y = 40;  
timeBut.alpha = 0.01;  
  
local function delay\_trans(event)  
 storyboard.gotoScene( "maths\_dif", "slideLeft", 1000)  
end  
   
function gameOver()  
 if countDown == 0 then  
 countDown = 0  
 currentTime = countDown  
 timerText.text = countDown  
 timer.performWithDelay(3000, delay\_trans)  
 end  
 timerText.text = countDown  
 currentTime = countDown  
 countDown = countDown - 1  
end  
   
Timer1 = timer.performWithDelay( 1000, gameOver, 11 )  
   
local function timeButton( event )  
if event.phase == "began" then  
  
 if resumeTime == true then  
 timer.pause( Timer1 )  
 pauseTime = true  
 resumeTime = false  
 pauseBtn.alpha = 1;  
 resumeBtn.alpha = 0;  
 elseif pauseTime == true then  
 timer.resume(Timer1)  
 pauseTime = false  
 resumeTime = true  
 pauseBtn.alpha = 0;  
 resumeBtn.alpha = 1;  
 end  
end  
end  
   
timeBut:addEventListener( "touch", timeButton )  
  
  
end  

[import]uid: 208811 topic_id: 35004 reply_id: 335004[/import]

Hi,
Obviously, this warning happens because the timer is not pause.
when countdown = 0 there is 3 sec delay before transition to the next scene,

I believe the warning happens when you click timeBut during this time. If so, the timer had already ended which make the pause/resume pointless.
Try remove the event listener to prevent user from clicking during this delay.
[lua]function gameOver()
if countDown == 0 then
timeBut:removeEventListener( “touch”, timeButton ) – add this
countDown = 0
currentTime = countDown
timerText.text = countDown
timer.performWithDelay(3000, delay_trans)
end
timerText.text = countDown
currentTime = countDown
countDown = countDown - 1
end[/lua]

It is also a good practice to remove all listeners before changing scene.

burhan [import]uid: 74883 topic_id: 35004 reply_id: 139249[/import]

Thanks for the reply Burhan, I was removing the event listener in the exitScene function but I placed it where you suggested. I am not getting the warning now, but my pause/play image is stuck on pause for the next use [import]uid: 208811 topic_id: 35004 reply_id: 139306[/import]

Hi,
Did remove your display object on ExitScene?
[lua]display.remove( object )[/lua]

or

Your variables pauseTime/ resumeTime which you set as globals.
You can set to local and have another local variables on new scene.
But if you have to use them as global (not advisable) then reset their values to initial values on enter scene.

burhan [import]uid: 74883 topic_id: 35004 reply_id: 139319[/import]

Hi,
Obviously, this warning happens because the timer is not pause.
when countdown = 0 there is 3 sec delay before transition to the next scene,

I believe the warning happens when you click timeBut during this time. If so, the timer had already ended which make the pause/resume pointless.
Try remove the event listener to prevent user from clicking during this delay.
[lua]function gameOver()
if countDown == 0 then
timeBut:removeEventListener( “touch”, timeButton ) – add this
countDown = 0
currentTime = countDown
timerText.text = countDown
timer.performWithDelay(3000, delay_trans)
end
timerText.text = countDown
currentTime = countDown
countDown = countDown - 1
end[/lua]

It is also a good practice to remove all listeners before changing scene.

burhan [import]uid: 74883 topic_id: 35004 reply_id: 139249[/import]

Thanks for the reply Burhan, I was removing the event listener in the exitScene function but I placed it where you suggested. I am not getting the warning now, but my pause/play image is stuck on pause for the next use [import]uid: 208811 topic_id: 35004 reply_id: 139306[/import]

Hi,
Did remove your display object on ExitScene?
[lua]display.remove( object )[/lua]

or

Your variables pauseTime/ resumeTime which you set as globals.
You can set to local and have another local variables on new scene.
But if you have to use them as global (not advisable) then reset their values to initial values on enter scene.

burhan [import]uid: 74883 topic_id: 35004 reply_id: 139319[/import]