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

How Long does an even survives.

Started by Flyin_Spaghetti, 07 January 2013 - 08:03 AM
Flyin_Spaghetti #1
Posted 07 January 2013 - 09:03 AM
If not caught, how long will an even linger around?

I am generally using a code like the following to do stuff:


while true do
e={os.pullEvent()}
if e[1]=='rednet_message' then
--do stuff--
end
if e[1]=='timer' then
--do stuff--
end
if e[1]=='monitor_touch' then
--do stuff--
end
end


which works fine in most cases. But if we imagine a situation where the part after pullEvent takes a longer time, I suppose it will be possible to miss events. How long, for instance, a key press remains as an even that can be caught? Also is there a way to put events on hold while having the computer do other things?
Lyqyd #2
Posted 07 January 2013 - 09:41 AM
Events are stored in a queue. You won't miss them unless you overflow the queue stack.
zekesonxx #3
Posted 07 January 2013 - 09:54 AM
Explanation:
Say there are two keypresses. The queue is now

key = keys.enter
key = keys.up
Then the code does os.pullEvent(), getting the first key event. The queue is now

key = keys.up
That key will continue to wait in the queue until another os.pullEvent or os.pullEventRaw is pulled.
ChunLing #4
Posted 07 January 2013 - 09:15 PM
Be alert to the fact that a good many functions provided by the CC api's pull and discard events until they get a specific type. So for example if you do a rednet.receive() or a read() to get some string input, all the events other than the "rednet_message" or "char" events needed by those functions get pulled and discarded.
Bogdacutu #5
Posted 08 January 2013 - 04:03 AM
Yeah, but for example if you use rednet.receive(), you obviously are only interested in rednet events, so there's no point in keeping all the other events is a queue. (that is certainly possible however)
ChunLing #6
Posted 08 January 2013 - 07:04 AM
Meh, sometimes people want to get all the events but forget that a particular function discards them.