kungfooman
kungfooman

Reputation: 4893

Timer() doesn't work with milliseconds

I need to call a function every 0.05 seconds, but Timer seems to have a lowest granularity of a second:

Timer(function(timer)
    print("Hai!\n") # executed once a second
end, 0.05, true)

Is there any way to make Timer work with milliseconds?

Upvotes: 1

Views: 65

Answers (1)

kungfooman
kungfooman

Reputation: 4893

Woops, the missing type declaration somehow made me think that the third "repeat" argument is a Bool, but it's actually the time. So true was converted to 1. Question "solved".

Correct:

Timer(function(timer)
    print("Hai!\n") # executed every 0.05 seconds now
end, 0, 0.05) # callback, delay time in seconds, repeat time in seconds

Upvotes: 2

Related Questions