3 posts
Posted 28 November 2013 - 11:45 PM
I am very new to computercraft, and I was experimenting with simple modem send and receive programs. I wanted to make a program that could wirelessly send text to another computer which would display it on a monitor, but I noticed that no matter what I sent, rednet.receive would always return 0. I am 100% sure that I did not mess up the id's on the computers and that all the modems were properly opened. I know they are connected because the receiving computer waits until the text is sent and then returns 0, no matter what the sent text was. Can someone help me?
8543 posts
Posted 28 November 2013 - 11:47 PM
Please post your code. You're probably not realizing that the first return value of rednet.receive is the ID of the sending computer.
3 posts
Posted 28 November 2013 - 11:53 PM
Sorry, I forgot.
Sending code:
Rednet.open("back")
Msg = io.read()
Rednet.send(22, msg)
Receiving code:
Rednet.open("back")
Local msg = rednet.receive()
Write(msg) --I downgraded it to write() because I was having unrelated problems with the monitor
Edited by
8543 posts
Posted 29 November 2013 - 12:19 AM
As I said, the first return value from rednet.receive() is the ID of the sending computer. Try catching the ID as well as the message and you'll have better luck:
rednet.open("back")
local id, msg = rednet.receive() --# note the use of id as well as message to catch the appropriate return values.
write(msg)
3 posts
Posted 29 November 2013 - 12:20 AM
Thanks so much, I hope this works!