If you want to just print something after a delay:
sleep(seconds)
-- Everyone knows this one, but just to be clear
If you want to do something on a specific time:
-- Between 18.00 to 20.00
while true do
if os.clock() > 18 and
os.clock() < 20 then
do something
end
sleep(.5)
end
If you want to have a delay and don't want to pause the entire program:
local curTime = os.time()
local delay = 5 -- minutes I think
while true do
-- Your fancy program stuff
if curTime == os.time() + delay then
do something
end
-- More fancy stuff
end
Now if you already got a event system then you can take use of that:
-- Press enter to start clock
-- Press space to exit
local ev,p1,p2,p3
while true do
ev,p1,p2,p3 = os.pullEvent()
if ev == "key" then
if p1 == 28 then
os.startTimer(5) -- 5 seconds I think
print("Timer set!")
elseif p1 == 57 then
print("Canceling!")
break
end
elseif ev == "timer" then
print("Timer has reached it's timeout!")
end
ev,p1,p2,p3 = nil
end