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

Rednet Error: Expected Number

Started by martok111, 24 January 2015 - 03:43 AM
martok111 #1
Posted 24 January 2015 - 04:43 AM
Trying to set up a control network, and everything was working out fine, until this code


function listen()
  local id, msg, dst
   print("Listening")
  while(true) do
	id, msg, dst = rednet.receive(10)
		print("Received ", msg)
	if (msg == "toggle") then
	  redstone.setOutput("right", true)
	  sleep(0.6)
	  redstone.setOutput("right", false)
	else
	  rednet.send(id, "13")
	end
  end
end

gives the error rednet:39: Expected number

when it receives the senders message:


rednet.send(a[y]["send"], "toggle")

and the code outputs


Listening
Received

The msg variable is not output, and I tried printing id before Received, which caused neither of them to print.
Bubba #2
Posted 24 January 2015 - 04:47 AM
Please post your full code. This is not sufficient information to debug this problem well. For example, what is a[y]["send"]? I can only assume that it isn't a number since it is throwing that error. Unless of course the error doesn't occur on that line. We really need the full code.
Edited on 24 January 2015 - 03:48 AM
Bomb Bloke #3
Posted 24 January 2015 - 05:26 AM
rednet.receive(10) returns nil if no message is received within ten seconds. This means id, msg and dst all get set to nil, which leads to you trying to rednet.send "13" to a nil system ID.

You probably just want to use rednet.receive(), which won't return until a message comes in.
martok111 #4
Posted 24 January 2015 - 05:57 AM
rednet.receive(10) returns nil if no message is received within ten seconds. This means id, msg and dst all get set to nil, which leads to you trying to rednet.send "13" to a nil system ID.

You probably just want to use rednet.receive(), which won't return until a message comes in.

That was it, Thanks Bomb!!

Sorry, Bubba, I will post more context next time. My code is very poorly commented right now, it would have been a big mess to sort through.