Could anyone tell me how to do this?
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
rednet_message?
Started by bbqroast, 22 March 2012 - 06:44 PMPosted 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?
Could anyone tell me how to do this?
Posted 22 March 2012 - 07:57 PM
What do you mean by bind? Do you want to use the event?
Posted 22 March 2012 - 08:00 PM
os.queueEvent(event,params)?
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.
Liraal handled raising…
So to consume the event…
os.pullEvent(event) //This will wait until an event matching the parameter is raised.
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).
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).
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
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.
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.
Posted 23 March 2012 - 04:30 AM
Thanks,
I assume p2 is the message, what is p1?
I assume p2 is the message, what is p1?
Posted 23 March 2012 - 04:31 AM
p1 is the sending computers ID
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.
Posted 24 March 2012 - 10:40 AM
You can also use parallel.waitForAll(function1,function2,…) or parallel.waitForAny(function1,function2,…) i thinkPretty 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.