Advertisement
TechManDylan

Webpage turtle controller

Feb 16th, 2024 (edited)
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. -- Function to handle incoming commands
  2. local function handleCommand(command)
  3. if command == "forward" then
  4. turtle.forward()
  5. print("Moved forward")
  6. elseif command == "back" then
  7. turtle.back()
  8. print("Moved back")
  9. elseif command == "left" then
  10. turtle.turnLeft()
  11. print("Turned left")
  12. elseif command == "right" then
  13. turtle.turnRight()
  14. print("Turned right")
  15. elseif command == "up" then
  16. turtle.up()
  17. print("Moved up")
  18. elseif command == "down" then
  19. turtle.down()
  20. print("Moved down")
  21. elseif command == "mine" then
  22. turtle.dig()
  23. print("Block mined")
  24. else
  25. print("Unknown command:", command)
  26. end
  27. end
  28.  
  29. -- Main loop
  30. while true do
  31. -- Make a request to the web server
  32. local response = http.get("http://71.68.68.110/get-command")
  33.  
  34. -- If the request was successful and we received a command
  35. if response then
  36. local command = response.readAll()
  37. response.close()
  38.  
  39. if command then
  40. print("Received command:", command)
  41. handleCommand(command)
  42. end
  43. end
  44.  
  45. -- Wait for a short while before making the next request
  46. sleep(1)
  47. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement