Timer going down

Hi I’ve been trying to figure how to do a timer that goes. I know how to up time but I want to down going form 60, 59, 58…

I’ve got the code for going up

local t = display.newText( “60”, 115, 105, “ArialRoundedMTBold”, 160 )
t:setTextColor( 0, 0, 0 )

local timeDelay = 500

local t = display.newText( “60”, 115, 105, “ArialRoundedMTBold”, 160 )
t:setTextColor( 0, 0, 0 )
function t:timer( event )

local count = event.count

self.text = count

if count >= 90 then
timer.cancel( event.source ) – after the 20th iteration, cancel timer
end
end

timer.performWithDelay( timeDelay, t, -1 )

I’ve got the timer going up but how would I make it go down.
[import]uid: 17058 topic_id: 19263 reply_id: 319263[/import]

Hey there, try this;

[lua]display.setStatusBar( display.HiddenStatusBar )

local count = 60
local hasRun = 0

local t = display.newText( “60”, 115, 105, “ArialRoundedMTBold”, 160 )

local timeDelay = 500

function t:timer( event )

count = count-1
hasRun = hasRun+1

self.text = count

if hasRun >= 20 then
timer.cancel( event.source ) – after the 20th iteration, cancel timer
end
end

timer.performWithDelay( timeDelay, t, -1 )[/lua]

And please post your code in < lua > and < / lua > tags - without the spaces. (Much easier to read.)

Peach :slight_smile: [import]uid: 52491 topic_id: 19263 reply_id: 74347[/import]

@peach thanks for the sample timer that really worked for my app alot. I’m truly sorry for not appreciating your help. I appreciate a lot and I thank, thank you. :slight_smile: [import]uid: 17058 topic_id: 19263 reply_id: 74596[/import]

Hey,

No worries, I’m happy to help - thanks for the appreciation!

Peach :slight_smile: [import]uid: 52491 topic_id: 19263 reply_id: 74621[/import]