Guest User

Untitled

a guest
Apr 19th, 2013
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.53 KB | None | 0 0
  1. local function handle(res)
  2.     local actions = {
  3.         w = turtle.forward,
  4.         a = turtle.turnLeft,
  5.         s = turtle.back,
  6.         d = turtle.turnRight,
  7.         l = turtle.place,
  8.         j = turtle.dig,
  9.         i = turtle.up,
  10.         k = turtle.down
  11.     }
  12.  
  13.     if actions[res] ~= nil then
  14.         actions[res]()
  15.     end
  16. end
  17.  
  18. while true do
  19.     http.request("http://localhost:8080")
  20.  
  21.     local event, url, res = os.pullEvent()
  22.    
  23.     if event == 'http_success' then
  24.         handle(res:readAll())
  25.     elseif event == 'http_failure' then
  26.         printError("HTTP request failed.")
  27.         return
  28.     end
  29. end
Advertisement
Add Comment
Please, Sign In to add comment