Timer error

I am trying to change my timer’s name so it would be easy to cancel it but I am having issues .

local timeLimit = 20 timeLeft = display.newText(timeLimit, 160, 20, native.systemFontBold, 24) timeLeft:setTextColor(255,0,0) function timerDown() timeLimit = timeLimit-1 timeLeft.text = timeLimit if(timeLimit==0)then timerrr.cancel(timerrr) storyboard.gotoScene("maxtime", "fade", 400) end end timer timer=timerrr.performWithDelay(1000,timerDown,timeLimit)

This is the error I am getting 

        C:\Users\Brandon\Documents\Corona Projects\StopTheBall\game.lua:41: ‘=’

expected near ‘timer’

stack traceback:

        [C]: in function ‘error’

        C:\Users\Brandon\Documents\Corona Projects\StopTheBall\storyboard.lua:16

41: in function ‘gotoScene’

        C:\Users\Brandon\Documents\Corona Projects\StopTheBall\start.lua:21: in

function <C:\Users\Brandon\Documents\Corona Projects\StopTheBall\start.lua:19>

        ?: in function <?:221>

local timeLimit = 20
timeLeft = display.newText(timeLimit, 160, 20, native.systemFontBold, 24)
timeLeft:setTextColor(255,0,0)

function timerDown()
timeLimit = timeLimit-1
timeLeft.text = timeLimit
if(timeLimit==0)then
timerr.cancel(timerr)
storyboard.gotoScene(“maxtime”, “fade”, 400)
end
end

timerr=timer.performWithDelay(1000,timerDown,timeLimit)

local timeLimit = 20 timeLeft = display.newText(timeLimit, 160, 20, native.systemFontBold, 24) timeLeft:setTextColor(255,0,0) function timerDown() timeLimit = timeLimit-1 timeLeft.text = timeLimit if(timeLimit==0)then timerr.cancel(timerr) storyboard.gotoScene("maxtime", "fade", 400) end end timerr = timer.performWithDelay(1000,timerDown,timeLimit) 

That’s the code Scott posted but it’s formated properly. ( I’m sure it was a mistake )

The timer code you are using is the code me and Alex provided you a couple days ago. Please take another look at the thread here

https://forums.coronalabs.com/topic/62736-timercancel-problem/#entry325585

and read what we posted. Thanks!

[quote=“InfiSnyp,post:3,topic:339077”]

local timeLimit = 20 timeLeft = display.newText(timeLimit, 160, 20, native.systemFontBold, 24) timeLeft:setTextColor(255,0,0) function timerDown() timeLimit = timeLimit-1 timeLeft.text = timeLimit if(timeLimit==0)then timerr.cancel(timerr) storyboard.gotoScene("maxtime", "fade", 400) end end timerr = timer.performWithDelay(1000,timerDown,timeLimit) 

That’s the code Scott posted but it’s formated properly. ( I’m sure it was a mistake )

The timer code you are using is the code me and Alex provided you a couple days ago. Please take another look at the thread here

https://forums.coronalabs.com/topic/62736-timercancel-problem/#entry325585

and read what we posted. Thanks! [/quote]

Thanks InfiSnyp

I am on an iPhone (which is hard to format code on) and MacBook Pro is getting a battery replacement.

Ya i thought something wasn’t right. Awesome to know there are others so committed that even answer questions through mobile!

I am getting this error 

Runtime error

C:\Users\Brandon\Documents\Corona Projects\StopTheBall\game.lua:64: attempt to c

all field ‘cancel’ (a nil value)

stack traceback:

        C:\Users\Brandon\Documents\Corona Projects\StopTheBall\game.lua:64: in f

unction ‘_listener’

        ?: in function <?:167>

        ?: in function <?:221

I am using storyboard . Do I have to put it in the createScene or outside of it ?

Replace timerr with timer on timerr.cancel

Thanks it works now

But how do I remove the timer from my other two scenes ? When I click the ball it takes me to the other scene and shows the timer which I want it to do but when I start another level I want it to remove the timer and show a different one 

restart.lua

function scene:enterScene(event) Runtime:addEventListener("touch", touchScreen) end function scene:exitScene(event) storyboard.purgeScene("restart") storyboard.purgeScene("game") Runtime:removeEventListener("touch", touchScreen) end

game.lua

function scene:enterScene(event) Ball:addEventListener( "tap", onBallTap ) end function scene:exitScene(event) Ball:removeEventListener( "tap", onBallTap ) end

maxtime.lua

function scene:enterScene(event) storyboard.purgeScene("game") end function scene:exitScene(event) end

When the game scene it goes into either the restart scene or the maxtime scene . In the maxtime scene it isn’t suppose to show the timer because that’s where i’m going to show the ads . In the restart scene , it’s suppose to show the time until I start a new level .

local timeLimit = 20
timeLeft = display.newText(timeLimit, 160, 20, native.systemFontBold, 24)
timeLeft:setTextColor(255,0,0)

function timerDown()
timeLimit = timeLimit-1
timeLeft.text = timeLimit
if(timeLimit==0)then
timerr.cancel(timerr)
storyboard.gotoScene(“maxtime”, “fade”, 400)
end
end

timerr=timer.performWithDelay(1000,timerDown,timeLimit)

local timeLimit = 20 timeLeft = display.newText(timeLimit, 160, 20, native.systemFontBold, 24) timeLeft:setTextColor(255,0,0) function timerDown() timeLimit = timeLimit-1 timeLeft.text = timeLimit if(timeLimit==0)then timerr.cancel(timerr) storyboard.gotoScene("maxtime", "fade", 400) end end timerr = timer.performWithDelay(1000,timerDown,timeLimit) 

That’s the code Scott posted but it’s formated properly. ( I’m sure it was a mistake )

The timer code you are using is the code me and Alex provided you a couple days ago. Please take another look at the thread here

https://forums.coronalabs.com/topic/62736-timercancel-problem/#entry325585

and read what we posted. Thanks!

[quote=“InfiSnyp,post:12,topic:339077”]

local timeLimit = 20 timeLeft = display.newText(timeLimit, 160, 20, native.systemFontBold, 24) timeLeft:setTextColor(255,0,0) function timerDown() timeLimit = timeLimit-1 timeLeft.text = timeLimit if(timeLimit==0)then timerr.cancel(timerr) storyboard.gotoScene("maxtime", "fade", 400) end end timerr = timer.performWithDelay(1000,timerDown,timeLimit) 

That’s the code Scott posted but it’s formated properly. ( I’m sure it was a mistake )

The timer code you are using is the code me and Alex provided you a couple days ago. Please take another look at the thread here

https://forums.coronalabs.com/topic/62736-timercancel-problem/#entry325585

and read what we posted. Thanks! [/quote]

Thanks InfiSnyp

I am on an iPhone (which is hard to format code on) and MacBook Pro is getting a battery replacement.

Ya i thought something wasn’t right. Awesome to know there are others so committed that even answer questions through mobile!

I am getting this error 

Runtime error

C:\Users\Brandon\Documents\Corona Projects\StopTheBall\game.lua:64: attempt to c

all field ‘cancel’ (a nil value)

stack traceback:

        C:\Users\Brandon\Documents\Corona Projects\StopTheBall\game.lua:64: in f

unction ‘_listener’

        ?: in function <?:167>

        ?: in function <?:221

I am using storyboard . Do I have to put it in the createScene or outside of it ?

Replace timerr with timer on timerr.cancel

Thanks it works now

But how do I remove the timer from my other two scenes ? When I click the ball it takes me to the other scene and shows the timer which I want it to do but when I start another level I want it to remove the timer and show a different one 

restart.lua

function scene:enterScene(event) Runtime:addEventListener("touch", touchScreen) end function scene:exitScene(event) storyboard.purgeScene("restart") storyboard.purgeScene("game") Runtime:removeEventListener("touch", touchScreen) end

game.lua

function scene:enterScene(event) Ball:addEventListener( "tap", onBallTap ) end function scene:exitScene(event) Ball:removeEventListener( "tap", onBallTap ) end

maxtime.lua

function scene:enterScene(event) storyboard.purgeScene("game") end function scene:exitScene(event) end

When the game scene it goes into either the restart scene or the maxtime scene . In the maxtime scene it isn’t suppose to show the timer because that’s where i’m going to show the ads . In the restart scene , it’s suppose to show the time until I start a new level .