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

Simultaneous event checking

Started by Railalis, 03 December 2012 - 07:57 AM
Railalis #1
Posted 03 December 2012 - 08:57 AM
Hello I am rather new to Lua and programming in computer craft. I am making a inventory program which acts somewhat like a sorting machine/bank/item retriever.

Essentially, I will have an input computer. Currently it detects red stone pulses which increase the inventory counter but also waits to receive an order from the control computer.

I am doing this via os.pullEvent()


while true do
event = os.pullevent()

if event == "redstone" then
  --do this
elseif event == "redstone_message" then
  --do that
end

end

If the computer receives a message then depending on it, will send a message back. Is there a way I can get the parameters of the redstone message on the event without using event, param1, param2, param3 = os.pullEvent() ?

I couldn't find anything pertaining to this when I looked around. Any help would be nice.
Grim Reaper #2
Posted 03 December 2012 - 09:24 AM
I'm not entirely sure what you're asking, but if you're looking to not anticipate what parameters you will be then you can capture the event and all
of its returned parameters in a table:

event = {os.pullEvent()}

It also would seem that you're looking for an event called "redstone_message" which is a non-existent event. If you're looking to receive messages that can be used as strings then you might want to look into rednet.

The "redstone" event is only triggered when a redstone pulse comes in contact with the computer, and unfortunately the side on which the pulse came into contact with is not returned as a parameter.
Railalis #3
Posted 03 December 2012 - 09:39 AM
Yea my bad. I was trying to simplify what I already have written but it waits either for a redstone pulse or a rednet message. Sorting the params into a table will probably solve what I am looking for. I will have to research those now. Thanks :D/>
ChunLing #4
Posted 03 December 2012 - 09:41 AM
You could use event = {os.pullEvent()} Hah, ninja'd

Then event is a table, with event[1] containing the event type and the other entries containing the rest of the event parameters.

But this isn't really all that superior to just supplying enough variables to match all the extra returns you might actually use, at least for your purposes.