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

[SOLVED] is there a better way around this

Started by Cozzimoto, 31 August 2012 - 04:07 PM
Cozzimoto #1
Posted 31 August 2012 - 06:07 PM
the turtle starts within range of the console of course but
i am trying to make a code for a turtle that if it goes out of range of the console it will report to the console saying it is out of range and turn off the rednet, and turn it back on when it is within range. i have a few vars here, the range var is the safe distance for the modem. since the modems range is a circle of 64 blocks out a maxium distance for a cube in a circle is 44. the next var is xCoord, zCoord, and yCoord which tracks the turtles coordinates. ServerX, ServerZ, ServerY keeps track of where the main console is at. if this is possible get back to me. if there is an easier way let me know. im having issues trying to figure out how to lay it all out.



range = 44

xCoord = 0
zCoord = 0
yCoord = 0

ServerX = 0
ServerZ = 0
ServerY = 0

if xCoord > (ServerX + range) or xCoord < (ServerX - range) then
  rednet.send(id, "is now out of the servers Network range.")
  rednet.close(side)

else
  rednet.open(side)
  rednet.announce()
end

if yCoord > (ServerY + range) or yCoord < (ServerY - range) then
  rednet.send(id, "is now out of the servers network range.")
  rednet.close(side)

else
  rednet.open(side)
  rednet.announce()

end

if zCoord > (ServerZ + range) or zCoord < (ServerZ - range) then
  rednet.send(id, "is now out of the servers network range.")
  rednet.close(side)

else
  rednet.open(side)
  rednet.announce()

end
Matrixmage #2
Posted 31 August 2012 - 06:33 PM
Couldn't you just have it periodically ping the main console and when the console doesn't get a ping after a amount of time it will think that the turtle is out of range and print that on the console (if that's what you want)

About turning off rednet, you would probably still need the rednet on so that it can know when it's in range
Cozzimoto #3
Posted 31 August 2012 - 06:43 PM
wow thats a simple way to do it. lol =)