Corona SDK, Timer pause and resume does not work?

My timer pause and resume does not work? it has a logical error which said WARNING:timer.resume(timerID)ignored b/c was not paused. Any idea? Should i add add or remove listener to remove to stop the transition of the timer?

local timerEnabled = true -- Stops or allows our countdown timer local touchEnabled = false local delay\_timer local timer\_trans -- transition of my timerbar local timer\_rect --display object local timer\_bar -- display object function pauseGame( ) if (timerEnabled==false) then timer.pause(timer\_bar) answer\_rect:removeEventListener( "touch", buttonTouched ) elseif (timerEnabled==true) then timer.resume(timer\_bar) answer\_rect:addEventListener( "touch", buttonTouched ) end end local pauseButtonPress = function( event ) pauseGame() end timer\_rect = display.newRect(uiGroup, \_W\*0.5, question\_rect.y+question\_rect.height, \_W, 50 ) timer\_rect.anchorY = 0 timer\_rect:setFillColor(0,0.3,0.7) if timerEnabled == true then timer\_bar = display.newRect(uiGroup, 0, timer\_rect.y+timer\_rect.height-20, \_W, 35) timer\_bar.anchorX = 0 timer\_bar:setFillColor(0.8,1,1) end pauseButton= widget.newButton{ defaultFile = "images1/Buttons/Pause.png", overFile= "images1/Buttons/Resume.png", onRelease = pauseButtonPress, } pauseButton.x = 100 pauseButton.y = 90 pauseButton.xScale = .6 pauseButton.yScale = .6

You need to pass the ID to pause, not the object.

https://docs.coronalabs.com/api/library/timer/pause.html
 

local timerId = timer.performWithDelay( 2000, function() end ) timer.pause( timerId )

Also, where are you starting the timer. I don’t see that code.

If at first you don’t succeed, read, read, read the API…

You need to pass the ID to pause, not the object.

https://docs.coronalabs.com/api/library/timer/pause.html
 

local timerId = timer.performWithDelay( 2000, function() end ) timer.pause( timerId )

Also, where are you starting the timer. I don’t see that code.

If at first you don’t succeed, read, read, read the API…