This is the code for a simple, should work sender and receiver, the first time I used this code it worked, but once the turtle gets out of range and places a computer, and I set that computer to running the same response program the turtle refuses to work more then once.
This is the code
-- sender/repeater
local id, msg, dist
rednet.open("top")
while true do
event, id, message = os.pullEvent()
if event == "rednet_message"
then
print("received from "..id)
rednet.send(id,"Received")
end
end
this is the turtle's program.
rednet.open("right")
local id, msg, dist
while not turtle.detectDown() do
turtle.down()
end
while true do
id = nil
msg = nil
dist = nil
turtle.forward()
rednet.broadcast("ping!")
id, msg, dist = rednet.receive(2)
sleep(1)
if msg == nil then
print("out of range")
turtle.back()
turtle.up()
turtle.select(1)
turtle.placeDown()
turtle.up()
turtle.select(2)
turtle.placeDown()
turtle.forward()
break
else
print(dist.." blocks away from "..id)
end
end
The idea is that I want a computer that simply sends a reply when receiving a rednet broadcast or send
and I want the turtle to walk away from that computer, then when its out of range place a new computer, which then can be set up as a new sender/repeater
and then rinse repeat, same process once the new computer is running the sender/repeater program, but for some reason it messes up and there is only one 'received' on the new computer