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

Rednet.send Trouble

Started by mrpoopy345, 24 November 2013 - 04:26 PM
mrpoopy345 #1
Posted 24 November 2013 - 05:26 PM
Hello! What I have for you today might be, wait for it,
THE NOOBIEST QUESTION EVER!
I am making a system where a computer sends the word 'help' to another computer
and the receiving computer prints out the id of the person who sent them it. Don't ask why.
It shows the receiving computer is receiving something, but it is not printing.

Sending computers code:

rednet.open("top")
print("ID:")
local id = tonumber(read())
print("Message:")
local m = tonumber(read())
rednet.send(id, m)
Receiving computer's code:

rednet.open("top")
while true do
  id, message = rednet.receive()
   if message == "help" then
   print("This ID needs help:")
   print(id)
  else
	rednet.send(id, "Please send 'help' for troubleshooting.")
end
end
If you need more information feel free to tell me!
Lyqyd #2
Posted 24 November 2013 - 05:37 PM
Don't tonumber the message. tonumber("help") returns nil.
mrpoopy345 #3
Posted 24 November 2013 - 05:42 PM
But if I just do read() It says rednet:53:Expected number
Bomb Bloke #4
Posted 24 November 2013 - 05:45 PM
He said the message, not the ID - "rednet.send()" only needs one number.
Papa_Beans #5
Posted 25 November 2013 - 11:57 AM
Hello! What I have for you today might be, wait for it,
THE NOOBIEST QUESTION EVER!
I am making a system where a computer sends the word 'help' to another computer
and the receiving computer prints out the id of the person who sent them it. Don't ask why.
It shows the receiving computer is receiving something, but it is not printing.

Sending computers code:

rednet.open("top")
print("ID:")
local id = tonumber(read())
print("Message:")
local m = tonumber(read())
rednet.send(id, m)
Receiving computer's code:

rednet.open("top")
while true do
  id, message = rednet.receive()
   if message == "help" then
   print("This ID needs help:")
   print(id)
  else
	rednet.send(id, "Please send 'help' for troubleshooting.")
end
end
If you need more information feel free to tell me!
Okay, I will help you understand since I am new like you. Rednet.send() looks for an ID and a message. That ID is a computer id, and the message is some sort of text.

When you set
m = tonumber(read())
you are making the message, or text, a number. That makes the receiving PC not get the message "help" .


Instead, type
m = read()
that will automatically convert the user input into a string.


Hope I helped! Enter key is broken, sorry if this is smushed. Please +1 if I helped, want to show I am helping this forum grow :)/> ~Papa Beans


EDIT*** Enter key working now!
Edited on 25 November 2013 - 11:01 AM