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

Computercraft RedNet Error

Started by jushymaso222, 03 March 2018 - 10:06 PM
jushymaso222 #1
Posted 03 March 2018 - 11:06 PM
Hello!
I'm trying to create a silo launch system. I want to have a master computer(controller) send a signal to the slave computers(silos) of weather or not they are armed. I also want the master computer to send a launch(for all silos to launch) or a launch[Number](for the one silo to launch) command to the slaves to launch them. I set it up how I think is most efficient but, I keep getting a rednet:109: Expected number. I am stuck and don't know what to do.

Slave:


rednet.open("right")
local armed = "false"
local silonum = 2
function fire()
  if armed == "true" then
    rs.setOutput("back", true)
    rs.setOutput("left", true)
    sleep(5)
    rs.setOutput("back", false)
    rs.setOutput("left", false)
  else
    print("Deactivated")
  end
end
while true do
  id, msg = rednet.receive(id, msg)
  if id == 28 and msg == "armed" then
    rs.setOutput("front", false)
    armed = "true"
  elseif id == 28 and msg == "unarmed" then
    rs.setOutput("front", true)
    armed = "false"
  elseif id == 28 and msg == "launch" then
    fire()
  elseif id == 28 and msg == "launch2" then
    fire()
  end
end
   

The master computer works fine but I figured I'd give you an idea what is going on inside of it…
Master:


--This is only the code for one of the slave computers in this case 2
local silo2 = "Deactivated"
while true do
  input2 = read()
  if input2 == "/launch" then --sends to all active
    rednet.broadcast("launch")
  if input2 == "/launch2" then --sends to specific silo (2)
    rednet.send(siloID, "launch2")
  if input2 == "/activate Silo #2" then
    print("Silo #2 now Activated")
    silo2 = "Activated"
    rednet.send(siloID, "armed")
  if input2 == "/deactivate Silo #2" then
    print("Silo #2 Deactivated")
    silo2 = "Deactivated"
    rednet.send(siloID, "unarmed")
-- Down here would be to launch and all that, this part works
   

Thank you in advance!
Bomb Bloke #2
Posted 04 March 2018 - 06:34 AM
rednet.receive() can be called in one of four ways:

rednet.receive()                  --# No parameters. Blocks execution until any message arrives.
rednet.receive(<number> timeOut)  --# Blocks execution until a message is received, or the specified number of seconds have passed (whichever is first).
rednet.receive(<string> protocol) --# Blocks execution until a message with the specified protocol is received.
rednet.receive(<string> protocol, <number> timeOut) --# Blocks execution until a message with the specified protocol is received, or the specified number of seconds have passed (whichever is first).

When your loop first runs, both id and msg are nil (because they haven't been assigned anything yet), so you probably don't error. On the second iteration, though, you'll be doing this:

rednet.receive(<number> id, <string> lastMsg)

… which isn't anything that function expects, hence the error. It looks like you just want to be using "rednet.receive()".