Timer count up

I have a timer that goes down . But how do I get one that counts up ?

timer countdown

local timeLimit = 30 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 display.remove(timeLeft) timer.cancel(timerr) storyboard.gotoScene("maxtime", "fade", 400) end end timerr = timer.performWithDelay(1000,timerDown,timeLimit)

What about you just put a + sign?

timeLimit = timeLimit +1

I tried that but it still counts down

Just try:

local timeLimit = 30 local currentTime = 0 local timerUpTimer local currentTimeText = display.newText(timeLimit, 160, 20, native.systemFontBold, 24) currentTimeText:setTextColor(255,0,0) local function timerUp() currentTime = currentTime + 1 currentTimeText.text = currentTime if currentTime \>= timeLimit then display.remove(currentTimeText) timer.cancel(timerUpTimer) storyboard.gotoScene("maxtime", "fade", 400) end end timerUpTimer = timer.performWithDelay(1000, timerUp, 0)

Like that you can cancel the timer from the outside or when the timeLimit is reached.

That one show the timeLimit at the top of the screen and it makes my app bug

Well, slight mistake on my side:

local timeLimit = 30 local currentTime = 0 local timerUpTimer local currentTimeText = display.newText(currentTime, 160, 20, native.systemFontBold, 24) currentTimeText:setTextColor(255,0,0) local function timerUp() currentTime = currentTime + 1 currentTimeText.text = currentTime if currentTime \>= timeLimit then display.remove(currentTimeText) timer.cancel(timerUpTimer) storyboard.gotoScene("maxtime", "fade", 400) end end timerUpTimer = timer.performWithDelay(1000, timerUp, 0)

Concerning the bug, I think it relates to how other stuff in your scene is set up.

Because if I run this code (excluded the storyboard call), it runs perfectly fine.

yea I fixed it . Thanks a lot

What about you just put a + sign?

timeLimit = timeLimit +1

I tried that but it still counts down

Just try:

local timeLimit = 30 local currentTime = 0 local timerUpTimer local currentTimeText = display.newText(timeLimit, 160, 20, native.systemFontBold, 24) currentTimeText:setTextColor(255,0,0) local function timerUp() currentTime = currentTime + 1 currentTimeText.text = currentTime if currentTime \>= timeLimit then display.remove(currentTimeText) timer.cancel(timerUpTimer) storyboard.gotoScene("maxtime", "fade", 400) end end timerUpTimer = timer.performWithDelay(1000, timerUp, 0)

Like that you can cancel the timer from the outside or when the timeLimit is reached.

That one show the timeLimit at the top of the screen and it makes my app bug

Well, slight mistake on my side:

local timeLimit = 30 local currentTime = 0 local timerUpTimer local currentTimeText = display.newText(currentTime, 160, 20, native.systemFontBold, 24) currentTimeText:setTextColor(255,0,0) local function timerUp() currentTime = currentTime + 1 currentTimeText.text = currentTime if currentTime \>= timeLimit then display.remove(currentTimeText) timer.cancel(timerUpTimer) storyboard.gotoScene("maxtime", "fade", 400) end end timerUpTimer = timer.performWithDelay(1000, timerUp, 0)

Concerning the bug, I think it relates to how other stuff in your scene is set up.

Because if I run this code (excluded the storyboard call), it runs perfectly fine.

yea I fixed it . Thanks a lot