Marech

Serveur_command_turtle

Jun 26th, 2015
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.12 KB | None | 0 0
  1. if pocket then
  2.     rednet.open("back")
  3.     write("pocket")
  4. else
  5.     rednet.open("top")
  6.     write("computer")
  7. end
  8.  
  9.  
  10. term.clear()
  11. term.setCursorPos(1,1)
  12.  
  13. continue = true
  14. monitor = nil
  15.  
  16. if pocket then
  17. else
  18.     monitor = peripheral.wrap( "right" )
  19.     monitor.clear()
  20.     monitor.setCursorPos(1,1)
  21.     monitor.write("Hello world")
  22. end
  23.  
  24. function attackInfinite()
  25.     write("Attacking forever, ctrl+T to stop")
  26.     if pocket then
  27.     else
  28.         monitor.clear()
  29.         monitor.setCursorPos(1,1)
  30.         monitor.write("Attacking forever,")
  31.         monitor.setCursorPos(1,2)
  32.         monitor.write("press q to stop")
  33.     end
  34.     while continue do
  35.         rednet.broadcast("attack")
  36.          
  37.         sleep(1)
  38.     end
  39. end
  40.  
  41. function exitProgram()
  42.      repeat
  43.        local ev, key = os.pullEvent('key')
  44.      until key == keys.q -- or whatever key i decide to use
  45.      monitor.clear()
  46.      monitor.setCursorPos(1,1)
  47.      monitor.write("Program stopped")
  48. end
  49.  
  50. function program()
  51.     while continue do
  52.         write("send a command to the turtles : ")
  53.         command = read()
  54.         if command == "attack" then
  55.             attackInfinite()
  56.         end
  57.         rednet.broadcast(command)
  58.     end
  59. end
  60.  
  61. parallel.waitForAny(program, exitProgram)
Advertisement
Add Comment
Please, Sign In to add comment