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

rednet messages + bundled cables

Started by slashv2, 08 March 2013 - 01:56 AM
slashv2 #1
Posted 08 March 2013 - 02:56 AM
Hi i only just started to work with wireless and i able to send a signal to a client computer and making it turn on or off a redstone signal…

I only just found out that there was a thing out there called Bundled cables and wanted to give them a try..

My question is this.. How would i write it so if i get the master computer to a send a msg saying "input 1"

the client computer would turn on lets say White.. and if input 2 then turn on red?
ikke009 #2
Posted 08 March 2013 - 08:23 AM
The first thing you will need to do is receive the message on the client computer
do this by opening the modem or whatever you are sending the message with follwing the command
partnerID, msg = rednet.receive()
this way the message is stored as the variable msg.

Next thing to do is to analyse the message, and act appropriately.
After that you will want the computer to wait for new messages. So in total something like this should do.
Also your bundled cable is on the left of the pc

local masterID = 1337 --insert computer id from master here
while true do
  local partnerID, msg = rednet.receive()
  if partnerID == masterID and msg == "input 1" then
    rs.setBundledOutput("left",colours.white)
  elseif partnerID == masterID and msg == "input 2" then
    rs.setBundledOutput("left",colours.red)
  elseif partnerID == masterID and msg == "reset" then
    rs.setBundledOutput("left",0)
  end
end
ChunLing #3
Posted 08 March 2013 - 03:25 PM
Note that if you have more than just a few options, it is more efficient to use a table indexed with the possible messages, like so:
local masterID = 1337 --insert computer id from master here
local output = {["input 1"] = colours.white,
["input 2"] = colours.red,
["reset"] = 0,}
while true do
    local partnerID, msg = rednet.receive()
    if partnerID == masterID and output[msg] then
        rs.setBundledOutput("left",output[msg])
    end
end
slashv2 #4
Posted 13 March 2013 - 04:58 AM
i owe you guys :D/> /hug