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

Rednet Send() Return Trouble

Started by hunterguy4, 12 November 2013 - 01:50 PM
hunterguy4 #1
Posted 12 November 2013 - 02:50 PM
Howdy all!

iv been writing a simple maseenger program between 2 coms and iv run into a bug. using a server to send data between the coms works fine, but i use a loop to check for incoming messages like so

a, b, = rednet.recieve(3)

if b ~= "" then
print( b )
end

now i recieve the message fine and it prints, but the "if string is blank" argument is not bieng ignored if no message is sent, printing a blank line in a loop. not a terrible bug but it does move the screen down and eventually the printed messages are lost to the upper part of the screen because the blank b bieng printed. any ideas if rednet.send() is sending somthing other then a blank string?
Edited on 12 November 2013 - 01:54 PM
Engineer #2
Posted 12 November 2013 - 02:54 PM
Can you show the complete code, please? Im asking that because I dont really understand what you are saying :l

If you are checking rednet for 3 seconds, in a loop, then you should consider to use events if you need to wait for a certain amount of time.
I will get more in-depth if you have shown your code, so I can give a more exact asnwer.
hunterguy4 #3
Posted 12 November 2013 - 02:56 PM
while true do
rednet.open("right")
a, b = rednet.recieve(3)

if b ~= "" then
print ( b )
end
end
Edited on 12 November 2013 - 01:57 PM
hunterguy4 #4
Posted 12 November 2013 - 02:58 PM
all message handling is server side and works ok, i just need to know why b is printing as an empty string but my ~= "" is supposed to prevent just that
Engineer #5
Posted 12 November 2013 - 03:57 PM
the second argument is a number, the ID of a computer.
Bomb Bloke #6
Posted 12 November 2013 - 04:26 PM
What second argument?

When you call rednet.receive(3), this tells it to either wait until a message comes in, or until three seconds have passed. In the latter case "b" doesn't get set to "", it gets set to nil. Your "if" statement doesn't check for this.

Solutions are to either use rednet.receive() (forcing it to wait until a message is received), or use something like "if b ~= "" and b~= nil then".
hunterguy4 #7
Posted 12 November 2013 - 05:29 PM
o ok b is nil, thats what i was missing thanks! i wasnt sure if nil and "" would be counted as the same but now i know