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

[Solved]Rednet Help

Started by FNCPro, 26 June 2013 - 07:48 AM
FNCPro #1
Posted 26 June 2013 - 09:48 AM
I need some help with Rednet because every time I try to send something via Rednet it requires me to send it 2 times…
Here are my programs on pastebin
Sending Program: http://pastebin.com/TVEzdd3e
Receiving Program: http://pastebin.com/nWxdhqr6

Solution by Bomb Bloke!
Spoiler
a, b, c = rednet.receive()
if rednet.receive() then

Both of these lines result in the system pulling a rednet message. You only want to call "rednet.receive()" once or else you will indeed need to send two.

Eg, use:

a, b, c = rednet.receive(5)
if a then

This will wait five seconds for a message. If one was not received in that time, "a" will be nil, so the conditional check will be false.
There is the solution he gave me and it worked. Hope that helps for anyone else.
FNCPro #2
Posted 26 June 2013 - 09:49 AM
Is there a way to prevent that without adding extra code?
Bomb Bloke #3
Posted 26 June 2013 - 09:54 AM
a, b, c = rednet.receive()
if rednet.receive() then

Both of these lines result in the system pulling a rednet message. You only want to call "rednet.receive()" once or else you will indeed need to send two.

Eg, use:

a, b, c = rednet.receive(5)
if a then

This will wait five seconds for a message. If one was not received in that time, "a" will be nil, so the conditional check will be false.
FNCPro #4
Posted 26 June 2013 - 09:56 AM
a, b, c = rednet.receive()
if rednet.receive() then

Both of these lines result in the system pulling a rednet message. You only want to call "rednet.receive()" once or else you will indeed need to send two.

Eg, use:

a, b, c = rednet.receive(5)
if a then

This will wait five seconds for a message. If one was not received in that time, "a" will be nil, so the conditional check will be false.
I will try that, Thanks!
FNCPro #5
Posted 26 June 2013 - 09:57 AM
Thank you! It worked, now I just need a forum mod to add this as solved/a solution.

That was the only way I knew on how to receive a message…
Bomb Bloke #6
Posted 26 June 2013 - 10:02 AM
Note that you could also simply forgo the conditional check, eg:

rednet.open("top")
while true do
  a, b, c = rednet.receive()
  print(B)/>
end

Without specifying a time for rednet.receive() to wait for, it'll wait forever or until a message is received. This means that you can be sure that something has come in by the time it progresses to the next line (ie, "b" should not be nil).