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

rednet_message?

Started by bbqroast, 22 March 2012 - 06:44 PM
bbqroast #1
Posted 22 March 2012 - 07:44 PM
Hey from what I understand LUA has a way I can bind this "event" (not the function) with your own function?
Could anyone tell me how to do this?
Wolvan #2
Posted 22 March 2012 - 07:57 PM
What do you mean by bind? Do you want to use the event?
Liraal #3
Posted 22 March 2012 - 08:00 PM
os.queueEvent(event,params)?
PatriotBob #4
Posted 22 March 2012 - 11:55 PM
Not sure if trying to consume or raise event….

Liraal handled raising…
So to consume the event…

os.pullEvent(event) //This will wait until an event matching the parameter is raised.
bbqroast #5
Posted 23 March 2012 - 01:27 AM
I want to bind the event to a function? Like when a rednet message appears it calls one of my own functions.
I don't want to make the program wait until it recieves the message thou (althrough if it most be done that way I'll do it).
Luanub #6
Posted 23 March 2012 - 02:07 AM
You will want to queue up a os.pullEvent() and then based on what is received in the message have it run the desired function



function doStuff()
do stuff
end

local event, p1, p2 = os.pullEvent("rednet_message")
if p2 == something then
   doStuff()
end

The code will stop and wait for the event. There might be a way to make it so it will not using the Coroutine or parallel API. I'm not to where I can play with it or I would give you an example.
bbqroast #7
Posted 23 March 2012 - 04:30 AM
Thanks,
I assume p2 is the message, what is p1?
Luanub #8
Posted 23 March 2012 - 04:31 AM
p1 is the sending computers ID
PatriotBob #9
Posted 23 March 2012 - 08:57 PM
Pretty sure you have to wait on the event to receive it. Lua only supports a single process at a time, so the way events are raised is by resuming a yielded coroutine. Nature of the beast I'm afraid.
Wolvan #10
Posted 24 March 2012 - 10:40 AM
Pretty sure you have to wait on the event to receive it. Lua only supports a single process at a time, so the way events are raised is by resuming a yielded coroutine. Nature of the beast I'm afraid.
You can also use parallel.waitForAll(function1,function2,…) or parallel.waitForAny(function1,function2,…) i think