Author Topic: Timer help?  (Read 3811 times)

0 Members and 1 Guest are viewing this topic.

Offline pianoman

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 426
  • Rating: +24/-0
  • ♪♫ ♪♫ ♪♫ ♪♫ ♪♫ ♪♫ ♪♫
    • View Profile
Timer help?
« 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

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Timer help?
« Reply #1 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".

Offline pianoman

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 426
  • Rating: +24/-0
  • ♪♫ ♪♫ ♪♫ ♪♫ ♪♫ ♪♫ ♪♫
    • View Profile
Re: Timer help?
« Reply #2 on: June 27, 2011, 09:42:54 am »
Oh, that makes sense.
I thought the period was how long it ran. :P
Thanks!

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Timer help?
« Reply #3 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() ;)