Posted 23 May 2013 - 05:27 PM
Hello pros :D/>
Need your help. Sitting here and want to finish an allmost finished and written project, but i am having trouble with the rednet :s
I am having a computer and a turtle. My goal is to let them communicate with no risk of failing, which means that i want to let them know about each other if they received the message or not.
I tried these functions:
TURTLE
COMPUTER
The computer sends a rednet message to the turtle. The turtle might work and cant receive a message until it finished its job. That means the computer has to send the message (over and over again) until the turtle received it.
If the turtle is receiving it, it sends a rednetmessage back ("successful").
The computer waits for this message and if it doesnt appear after a given amount of time it sends the message again. If the computer gets a message it is fine and exits the function.
If i test this now, the turtle spits out "Hello", but the computer doesnt care about the safety message and keeps going and sends "Hello" over rednet. What i am doing wrong?
Are there even better ways to do this…
Thank you
unobtanium
Need your help. Sitting here and want to finish an allmost finished and written project, but i am having trouble with the rednet :s
I am having a computer and a turtle. My goal is to let them communicate with no risk of failing, which means that i want to let them know about each other if they received the message or not.
I tried these functions:
TURTLE
computerID = 3
turtleID = 4
function receiveMessage()
while true do
local senderChannel, msg = rednet.receive()
if senderChannel == computerID then
rednet.send(turtleID,"successful")
return msg
end
end
end
print(receiveMessage())
COMPUTER
computerID = 3
turtleID = 4
function sendMessage(sendingmessage)
while true do
rednet.send(computerID,sendingmessage)
local senderChannel, msg = rednet.receive(2)
if senderChannel == turtleID then
return msg
end
end
end
print(sendMessage("Hello"))
The computer sends a rednet message to the turtle. The turtle might work and cant receive a message until it finished its job. That means the computer has to send the message (over and over again) until the turtle received it.
If the turtle is receiving it, it sends a rednetmessage back ("successful").
The computer waits for this message and if it doesnt appear after a given amount of time it sends the message again. If the computer gets a message it is fine and exits the function.
If i test this now, the turtle spits out "Hello", but the computer doesnt care about the safety message and keeps going and sends "Hello" over rednet. What i am doing wrong?
Are there even better ways to do this…
Thank you
unobtanium