21 posts
Posted 21 January 2013 - 08:27 AM
I'm making a simple program that's going to be part of a larger "mother" program. This bit is just the part that's suppose to receive rednet messages but i can't get it to work right.
print("Duration:")
local var = tonumber(read())
local senderId, message, distance = rednet.receive(var) -- Am I using var correctly?
write("From: ") -- I think these last three lines are the problem
print(senderId)
print(message)
I've been messing around with this code for a while now and it never returns an error message when I run it. It seems to work fine and it always waits the time I specify but when I send a message to this computer it doesn't stop waiting and it doesn't print the senderId or message.
7508 posts
Location
Australia
Posted 21 January 2013 - 08:29 AM
Var is used correctly there to timeout the receive. Are you opening rednet in the computer?
21 posts
Posted 21 January 2013 - 09:03 AM
I did make sure that both the sending and recieving computers were open. I also made sure I was using the right computer ID when I sent the test message. The computer looks like this when I run it.
Duration:
20 -- I enter the duration and it waits the correct time
--no matter how soon I send the message it still waits exactly the duration I entered and after the timeout is up it prints a blank line
> -- after that it just goes back to the normal ">" and waits for me to do something
2088 posts
Location
South Africa
Posted 21 January 2013 - 09:05 AM
Are you sure you didn't make a typo within the opening of the modems, and you didn't close them before sending?
Post both codes here so we can see them
21 posts
Posted 21 January 2013 - 11:14 AM
Are you sure you didn't make a typo within the opening of the modems, and you didn't close them before sending?
Post both codes here so we can see them
This is the program I used to open my connection. I assumed it was working because the modem lit up when I used it.
term.clear()
term.setCursorPos(1,1)
print("Do you want to open or close a connection?")
local var0 = read
if var0 == "open" then
print("Which side would you like to connect?")
local var1 = read()
rednet.open(var1)
end
if var0 == "close" then
print("Which side would you like to disconnect?")
local var2 = read()
rednet.close(var2)
end
21 posts
Posted 21 January 2013 - 11:29 AM
Ahhhhhhh! Sorry guys. I made a stupid.
The program I was using to send test messages looked like this:
print("Target ID:")
local var1 = tonumber(read())
print("Message:")
local var2 = read()
rednet.send(13,"have a fish",true) -- I slapped myself when I read this line
7508 posts
Location
Australia
Posted 21 January 2013 - 12:00 PM
Ahhhhhhh! Sorry guys. I made a stupid.
The program I was using to send test messages looked like this:
print("Target ID:")
local var1 = tonumber(read())
print("Message:")
local var2 = read()
rednet.send(13,"have a fish",true) -- I slapped myself when I read this line
Lol?