Advertisement
downwind

Turtle Listening Program for remote turtle in ComputerCraft

Oct 12th, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.47 KB | None | 0 0
  1. --Open rednet, make clearing the screen a single function
  2. rednet.open("right")
  3. function clear() term.clear() term.setCursorPos(1, 1) end
  4. while true do
  5. clear()
  6. print("Connected, ID: ", os.computerID(), ". Listening for requests.")
  7. rednet.broadcast("Listening") --Tell all other computers in the area that this turtle is ready and waiting for orders
  8. local id, msg = rednet.receive(10) --Wait for a return message for 10 seconds, then repeat
  9. if msg == "goto" then --If the incoming message is a goto request then prepare for coordinates (other commands can be added in this if statement in the future
  10.   print("Goto request from ", id, ", getting coordinates...")
  11.   local id, msg = rednet.receive()
  12.   gox = tonumber(msg) --Because only strings can be send over rednet the coordinates are changed to and from strings on each side of the message
  13.   local id, msg = rednet.receive()
  14.   goy = tonumber(msg)
  15.   local id, msg = rednet.receive()
  16.   goz = tonumber(msg)
  17.   print("Coordinates received, going to ", gox, " ", goy, " ", goz)
  18.   shell.run("goto.lua", gox, goy, goz) --Run the goto program with the received coordinates
  19.   end
  20. --additional functions can be added
  21. if msg == "gohome" then -- my go home command
  22.     print("Goto request from ", id, ", going HOME!")
  23.     shell.run("gohome.lua") -- run my gohome.lua
  24.     end
  25.  
  26. if msg == "gocomp" then -- my go to computer command
  27.     print("Goto request from ", id, ", going to Main Computer!")
  28.     shell.run("gotopc.lua") -- run my gohome.lua
  29.     end
  30.  
  31. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement