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

Events from coroutines not showing

Started by gajbooks, 08 August 2015 - 11:16 PM
gajbooks #1
Posted 09 August 2015 - 01:16 AM
I'm making a thing with co-routines, but whenever I call os.queueEvent from the co-routine the parent thread doesn't get the event. I'm probably misunderstanding how os.queueEvent works. I could probably communicate through coroutine.yield, but at this point I'm just interested in why it doesn't work.
Bomb Bloke #2
Posted 09 August 2015 - 01:23 AM
The event will be available to the parent coroutine. Whether it successfully catches it depends on your own code.
gajbooks #3
Posted 09 August 2015 - 01:40 AM
Can one queue an event with a function as one of the arguments?
Bomb Bloke #4
Posted 09 August 2015 - 02:03 AM
That's one of those questions that'd be easiest to answer by testing it yourself, perhaps. ;)/>

But assuming the answer is "no", you could put the function(s) you wanted to queue into a table, then queue an event with the key name. Eg, something loosely along these sorts of lines:

local myFuncs = {
	["someFunc"] = function()
		-- do stuff
	end,
	
	["someOtherFunc"] = function()
		-- do more stuff
	end
}

os.queueEvent("runThisFunc", "someFunc")

while true do
	local myEvent = {os.pullEvent()}

	if myEvent[1] == "runThisFunc" then
		myFuncs[myEvent[2]]()
	elseif myEvent[1] == whatever -- etc...
gajbooks #5
Posted 09 August 2015 - 02:43 AM
Thank you for your help. I found out that you cannot pass functions through an event. Just turning the field to nil isn't really a good way to bring that to someones attention though.