259 posts
Posted 24 November 2013 - 03:01 PM
Is there a way directly using os.startTimer() to return how much time remains until it's done?
If not, what do you suggest? I have some ideas of how to do it that would work, but I want an efficient way.
1688 posts
Location
'MURICA
Posted 24 November 2013 - 03:12 PM
You could use os.clock(), then add the length of the timer to get when the timer will end. Then when you need to check how much time you have left, subtract the end time and the current time (os.clock()). Here's an example:
local period = 10
local timer = os.startTimer(period)
local endTime = os.clock() + period
while true do
local ev, p1 = os.pullEvent()
if ev == "key" then
print("Time left: ", endTime - os.clock())
elseif ev == "timer" and p1 == timer then
break
end
end
You can check the time left by pressing any key, and the loop breaks once the time is up.