Jump to content




Rednet Error: Expected Number


  • You cannot reply to this topic
3 replies to this topic

#1 martok111

  • Members
  • 4 posts

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.

#2 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

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 by Bubba, 24 January 2015 - 04:48 AM.


#3 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

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.

#4 martok111

  • Members
  • 4 posts

Posted 24 January 2015 - 05:57 AM

View PostBomb Bloke, on 24 January 2015 - 05:26 AM, said:

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.





3 user(s) are reading this topic

0 members, 3 guests, 0 anonymous users