Jump to content




[Programming][Lua][Question] Making a timer?


  • You cannot reply to this topic
6 replies to this topic

#1 EmTeaKay

  • Members
  • 115 posts

Posted 18 October 2012 - 09: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.

#2 Noodle

  • Members
  • 989 posts
  • LocationSometime.

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 EmTeaKay

  • Members
  • 115 posts

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 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 19 October 2012 - 01:25 PM

Edit: I actually don't know what you wanted ><

#5 digpoe

  • Members
  • 92 posts

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.

#6 faubiguy

  • Members
  • 213 posts

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 EmTeaKay

  • Members
  • 115 posts

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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users