zootsuitman

Web Turtles

Apr 22nd, 2016
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.86 KB | None | 0 0
  1. -- WEB TOTLES!
  2. -- Korbin Ancell 1/25/2016
  3.  
  4. local direction = 'f'
  5. local headers = {
  6.     ["User-Agent"] = "turtle",
  7.     ["firstTime"] = "true"
  8. }
  9.  
  10. function clear()
  11.     term.clear()
  12.     term.setCursorPos(1,1)
  13. end
  14.  
  15. clear()
  16. print("Waiting for Scottie to beam down the next instruction")
  17.  
  18. local input = http.get("http://zsi.duckdns.org/webturtle.php", headers)
  19. headers["firstTime"] = "false"
  20.  
  21. while(true) do
  22.     while(true) do
  23.  
  24.         sleep(.5)
  25.         input = http.get("http://zsi.duckdns.org/webturtle.php", headers)
  26.    
  27.         local msg = input.readAll()
  28.        
  29.         if msg == "nil" then break end
  30.  
  31.     --Movement--
  32.         if msg == "f" then turtle.forward() break end
  33.         if msg == "b" then turtle.back() break end
  34.         if msg == "r" then turtle.turnRight() break end
  35.         if msg == "l" then turtle.turnLeft() break end
  36.         if msg == "u" then turtle.up() break end
  37.         if msg == "d" then turtle.down() break end
  38.        
  39.     --Actions--
  40.         if msg == "m" then
  41.             if direction == "f" then turtle.dig() break end
  42.             if direction == "u" then turtle.digUp() break end
  43.             if direction == "d" then turtle.digDown() break end
  44.         end
  45.        
  46.         if msg == "place" then
  47.             if direction == "f" then turtle.place() break end
  48.             if direction == "u" then turtle.placeUp() break end
  49.             if direction == "d" then turtle.placeDown() break end
  50.         end
  51.        
  52.         if msg == "pickup" then
  53.             if direction == "f" then turtle.suck() break end
  54.             if direction == "u" then turtle.suckUp() break end
  55.             if direction == "d" then turtle.suckDown() break end
  56.         end
  57.        
  58.     --Directions--
  59.         if msg =="mf" then direction ="f" break end
  60.         if msg =="md" then direction ="d" break end
  61.         if msg =="mu" then direction ="u" break end
  62.        
  63.     --Exit--
  64.         if msg =="exit" then os.reboot() end
  65.     end
  66. end
Advertisement
Add Comment
Please, Sign In to add comment