113 posts
Posted 18 October 2012 - 10:56 PM
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.
864 posts
Location
Sometime.
Posted 18 October 2012 - 10: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
113 posts
Posted 18 October 2012 - 11:26 PM
This is great, except I can't type, let's say, a password. Other than that, this is great.
2088 posts
Location
South Africa
Posted 19 October 2012 - 02:25 PM
Edit: I actually don't know what you wanted ><
92 posts
Posted 19 October 2012 - 02: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.
231 posts
Posted 19 October 2012 - 03: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)
113 posts
Posted 19 October 2012 - 08: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.