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

os.pullEvent() dropping parameters?

Started by OreCruncher, 01 January 2013 - 06:54 AM
OreCruncher #1
Posted 01 January 2013 - 07:54 AM
Hey all! I have been beating my head against this particular problem for better part of two days. So before I go bloody my nose some more I figured I would post the problem I am experiencing in hopes that someone has a clue for me.

The issue is with os.queueEvent() and os.pullEventRaw(). I post an event using queueEvent(), and that event has a table as one of the event parameters. When I pull the event using pullEventRaw(), the parameter for the table is nil.

Here is some demonstration code:


os.queueEvent("start")
while true do
local event = { os.pullEventRaw() }

if event[1] == "terminate" then
  print("terminating...")
  return
elseif event[1] == "start" then
  print("starting")
  os.queueEvent("end", 1, 2, 3, 4, 5, {1})
elseif event[1] == "end" then
  print("ending")
  for i,v in pairs(event) do
   print(string.format("%s=%s", tostring(i), tostring(v)))
  end
  os.queueEvent("terminate")
end
end

I would expect the last print in the loop to print something like "table", but nothing is emitted.
Cloudy #2
Posted 01 January 2013 - 08:11 AM
Yeah, you can't queueEvent tables.
OreCruncher #3
Posted 01 January 2013 - 08:22 AM
Yeah, you can't queueEvent tables.

*whines*

This is going to make my code look ugly. Thanks!
OreCruncher #4
Posted 01 January 2013 - 08:40 AM
For those that may be in the same situation… They way I worked around this is to cache the table event data in another non-local table, and then pass the integer index to that entry with the event. When the event finally gets processed, just index back into the cache table to fetch the information.