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

Having trouble with a Rednet Program

Started by survivalstevee, 28 June 2015 - 07:49 PM
survivalstevee #1
Posted 28 June 2015 - 09:49 PM
Recently I have been creating a large Rednet program. Everything has been working fine up until i got to the "receive" function.


Code:
print("How long would like to Receive?")
Num2 = read()
local senderId, message, protocol = rednet.receive(Num2)
print(message)
print("sent from " .. senderId)
end

I expected it to allow input for an integer which would determine the length at which the receive would last.
and afterwards for it to display the message and the id of the sending computer.

Instead, the computer goes into the receive state (the cursor disapears and waits for a message to receive.) except it ignores the duration set by the variable 'Num2', and lasts infinitely unless you terminate it. it also does not receive any messages that are sent to it.

if you have any further questions that would help i will answer them.

~survivalstevee
The_Cat #2
Posted 28 June 2015 - 10:48 PM
(Make sure the modems are open :)/>, rednet.open("sideOfModem"))
On the sending program are you using "rednet.send()" or "rednet.broadcast()"?

For it ignoring the timer try doing "rednet.receive(tonumber(Num2))"
Edited on 28 June 2015 - 08:52 PM
Bomb Bloke #3
Posted 29 June 2015 - 01:02 AM
Cat's suggestion of using tonumber() should do the trick. read() returns a string, and if you only pass a string to rednet.receive(), then it assumes it should wait indefinitely for a message using that string as its protocol.
survivalstevee #4
Posted 29 June 2015 - 04:13 AM
(Make sure the modems are open :)/>, rednet.open("sideOfModem"))
On the sending program are you using "rednet.send()" or "rednet.broadcast()"?

For it ignoring the timer try doing "rednet.receive(tonumber(Num2))"

To answer your question, I used rednet.send()
the exact code is rednet.send(6, "Test")

thanks for the suggestion, ill try it out.
survivalstevee #5
Posted 29 June 2015 - 04:37 AM
(Make sure the modems are open :)/>, rednet.open("sideOfModem"))
On the sending program are you using "rednet.send()" or "rednet.broadcast()"?

For it ignoring the timer try doing "rednet.receive(tonumber(Num2))"

Thanks, after i tried it, it worked, one of My computers may have not had its rednet open.