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

Wireless modem receive withotu waiting? (Stalling)

Started by YoShIWoZ, 20 April 2014 - 01:07 PM
YoShIWoZ #1
Posted 20 April 2014 - 03:07 PM
Hey yall.
So first off. I'm fairly new to both computercraft and Lua.
Anyway i've managed to make an OS for touch monitors.
I've made a few programs for this touchOS
One of them being called "Lights" this program lets me control the light of my base using redstone (enderIO) from a computer.
So my mate made a base aswell, and wanted to be able to do the same, we made a control hub between our bases.
Where the "Master computer" is located.
So i installed my OS on both the master computer and my mates computer
What i wanted to do is have a "page" in my "Lights" program that would control the lights in his base.
Aswell as being able to control the lights in his base, from his computer.
I can (easily) think of a way to do this, but i've run into a wall.
The reason for this is: When i use either modem_message og rednet_message on his computer the OS stalls, since the modem is waiting to receive sometehing ie.
rednet.receive()

problem is if i use rednet.receive() It will wait till it's gotten a message from the "main" computer, making my os unuseable while waiting.

So my question is: Is there any way/code/command/api that makes it possible to to send commands through the network without the receiver having to wait and stall the rest of the code till it gets it's "reply"?

here is my code that i have inside the loop that runs the touch os.

rednet.open("top")

id,message = rednet.receive()
  if id == 0 then --0 is the Id of the main pc
    if message == "mWorkroom" then
	  workroomLights = 1
	  programLights()
    end
  end
The programLights
has the code for if
workroomLights == 1
to
redstone.setOutput("right", true)
and if
workroomLights == 0
it will ofc. have the output set to false.

I hope this is to too messy or ununderstandable if there is any way i can explain myself better, or if there's anything you need to help me. Please let me know.

Much appreciated.
-YoShI
CometWolf #2
Posted 20 April 2014 - 08:30 PM
You seem to have misunderstood what rednet.receive actually is. It's a os.pullEvent of it's own, meaning yes it will freeze your computer until it times out or gets a rednet message. However, this also means you can easily intergrate your own into your event loop. Im guessing you know what im talking about here since you managed to make a touch based interface.

Alternatively you could just use the parallel API.
http://computercraft.info/wiki/index.php?title=Parallel_%28API%29
YoShIWoZ #3
Posted 21 April 2014 - 08:01 AM
Thanks for the reply, I figured this out while waiting for my post to approved. :)/>
I was allrdy using parallel's as my OS has a clock, so when i looked through my code, it striked me to do the same for this.
But thanks a ton for the tip! :)/>

- Solved!