PaffcioStudio

Turtle - Serwer

Feb 2nd, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.17 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("Polaczono, ID: ", os.computerID(), ". Czekam na klienta.")
  7. print("Upewnij sie, ze turtle ma zainstalowany program 'goto'")
  8. rednet.broadcast("Listening") --Tell all other computers in the area that this turtle is ready and waiting for orders
  9. local id, msg = rednet.receive(10) --Wait for a return message for 10 seconds, then repeat
  10. 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
  11.   print("Znaleziono klienta ", id, ", czekam na koordynaty.")
  12.   local id, msg = rednet.receive()
  13.   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
  14.   local id, msg = rednet.receive()
  15.   goy = tonumber(msg)
  16.   local id, msg = rednet.receive()
  17.   goz = tonumber(msg)
  18.   print("Koordynaty otrzymane, ide do ", gox, " ", goy, " ", goz)
  19.   shell.run("goto", gox, goy, goz) --Run the goto program with the recived coordinates
  20. end
  21. end
Add Comment
Please, Sign In to add comment