This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
mark332's profile picture

Need help: os.pullEvent() with Timeout

Started by mark332, 03 July 2013 - 02:01 PM
mark332 #1
Posted 03 July 2013 - 04:01 PM
Hi guys,

I'm currently writing on a server-system and I need an function like os.pullEvent() with a Timeout.

This is nearly working, but it breaks the loop after 1 to 3 seconds:


-- Notice: This is placed in my own API named "gen" so I can call it with gen.pullEvent()

function pullEvent(ExTimeOut, ExEvent)
local ExTimeOut = 3
if ExTimeOut > 1 then
timer = os.startTimer(ExTimeOut)
while true do
  event = {os.pullEvent()}
  if event  then
	if event[1] == ExEvent then
	 break
	end
  else
   break
  end

  if event[1] == "timer" and event[2] == timer then
   event[3] = "timeout!"
   break
  end
end
return event
end
end

Anyone know, how to fix it, or an alternative possibility to make an os.pullEvent with timeout?

mark332

PS: Sry, if my english is bad :)/> I'm german.
mark332 #2
Posted 03 July 2013 - 04:42 PM
Nevermind ;)/> I've fixed it:

Just remove…


[...]
		 break
		end
  -- else	   this...
--  break      and this line ;)/>
 end

  if event[1] == "timer" and event[2] == timer then
[...]