Topic: Timer in lua
Hi,
I am currently making time challenges for my game, but I don't know how to make a timer to count the seconds. Does anyone know how?
You are not logged in. Please login or register.
Hi,
I am currently making time challenges for my game, but I don't know how to make a timer to count the seconds. Does anyone know how?
Hello, to quote anael :
The lua script update is syncronised at 60fps
so you can create a timer with a simple variable like that :t = 0
function onSceneUpdate()
-- 1 second
if t == 60 then
print("one second")
endt = t+1
end
So you could do something like :
--print every seconds in the console
TIMER = {ms = 0, seconds = 0, onesec = 60}
function onSceneUpdate()
TIMER.ms = TIMER.ms + 1
if TIMER.ms == TIMER.onesec then
TIMER.ms = 0
TIMER.seconds = TIMER.seconds + 1
print(TIMER.seconds)
end
end
Thanks! But if the fps was lower than 60 wouldn't the timer be inaccurate?
onSceneUpdate is always launched 60 time per second, even if the fps are lower. so it's safe.
Okay good, thanks.
Powered by PunBB, supported by Informer Technologies, Inc.
Currently installed 3 official extensions. Copyright © 2003–2009 PunBB.