Omnimaga

Calculator Community => TI Calculators => Lua => Topic started by: pianoman on June 27, 2011, 09:33:58 am

Title: Timer help?
Post by: pianoman on June 27, 2011, 09:33:58 am
Hi everyone!
I was trying to make a timer that counts down from 30 every second, but it just got stuck on 30.
What is wrong here?
Code: [Select]
num=30

function on.paint(gc)
gc:drawString(num,0,0,"top")
timer.start(30)
end

function on.timer()
num=num-1
platform.window:invalidate()
end
Title: Re: Timer help?
Post by: Munchor on June 27, 2011, 09:37:36 am
From Lua Wiki:

Quote
timer.start(period) : Starts the timer with the given period (in seconds)

So, timer.start(30) calls the timer every 30 seconds, not "every second".
Title: Re: Timer help?
Post by: pianoman on June 27, 2011, 09:42:54 am
Oh, that makes sense.
I thought the period was how long it ran. :P
Thanks!
Title: Re: Timer help?
Post by: Munchor on June 27, 2011, 09:43:25 am
Oh, that makes sense.
I thought the period was how long it ran. :P
Thanks!

It runs forever, but you can stop it with timer.stop() ;)