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

[API][Question] Parallel and Event Details

Started by Ditto8353, 16 October 2012 - 06:23 PM
Ditto8353 #1
Posted 16 October 2012 - 08:23 PM
After looking at the code this looks to be, basically, an event distributor. The controller pulls an event and cycles through all coroutines created by the waitFor<Any | All>(). If a coroutine is requesting that event, it is passed to the coroutine.
Is this correct? I am trying to determine my options, and having a grasp on the parallel API will help with my decision. Essentially I want to simulate a read() call remaining open yet still be able to pull other events.

Perhaps I am going about this in the wrong way. Would this accomplish my goal better than parallel/coroutines?

while true do
   local input
   local evt = {os.pullEvent()}
   if evt[1] == "char" then input = input .. evt[2]
   elseif evt[1] == "key" then
      --'Process keys like Enter and Backspace and arrows'
   else
      --'You get the idea.'
   end
end

My main issue is that I don't want any events to go unnoticed. Does CC use an event queue? Or would an event be lost if it occurred while no pullEvent was active?
Doyle3694 #2
Posted 16 October 2012 - 08:36 PM
I think they get lost. atleast for example if you press a button and then start a os.pullEvent it won't register that keypress. don't know if timeouts or more important stuff like that will queue though
Kilobyte #3
Posted 16 October 2012 - 09:06 PM
CC definately uses a queue. and you can even push a custom even to it using os.queueEvent()
Cloudy #4
Posted 17 October 2012 - 12:40 AM
I think they get lost. atleast for example if you press a button and then start a os.pullEvent it won't register that keypress. don't know if timeouts or more important stuff like that will queue though

Don't post unless you're sure you know the answer. You've been doing that a lot lately. Stop it.