How do I make a timer? I know you can make a timer with os.startTimer(x). But I want a timer where you can still type and do other stuff in the program. Anyone know how to do this? If so, please respond. Thank you in advance.
[Programming][Lua][Question] Making a timer?
Started by EmTeaKay, Oct 18 2012 09:56 PM
6 replies to this topic
#1
Posted 18 October 2012 - 09:56 PM
#2
Posted 18 October 2012 - 09:57 PM
It triggers an event
os.startTimer(1)
while true do
event, p1 = os.pullEvent("timer")
if event then
break -- Or any code here
end
end
#3
Posted 18 October 2012 - 10:26 PM
This is great, except I can't type, let's say, a password. Other than that, this is great.
#4
Posted 19 October 2012 - 01:25 PM
Edit: I actually don't know what you wanted ><
#5
Posted 19 October 2012 - 01:46 PM
So basically a timed system for entering a password? like if you don't enter the password in 30 sec you get locked out of the computer?
Hmmm.. I belive coroutine would help. Although, i've never used it before so I do not know how to use it.
Hmmm.. I belive coroutine would help. Although, i've never used it before so I do not know how to use it.
#6
Posted 19 October 2012 - 02:47 PM
Try using parallel (which uses coroutine, but handles them for you):
local input = ""
function timeOut()
local timer = os.startTimer(30)
while true do
local event, param = os.pullEvent("timer")
if param = timer then break end
end
end
function getInput()
input = read("*")
end
parallel.waitForAny(timeOut, getInput)
#7
Posted 19 October 2012 - 07:37 PM
Thank you. I'll try this and get back to you on it. This should help.
EDIT: This does help! Thank you so much.
EDIT: This does help! Thank you so much.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











