Advertisement
Snowdingerr

controller

Mar 17th, 2023 (edited)
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.09 KB | Gaming | 0 0
  1. -- turtle must be initialized facing positive X axis
  2.  
  3. -- variables
  4. local x = 0
  5. local y = 0
  6. local z = 0
  7. local r = 0
  8.  
  9. -- local ws, err = http.websocket("ws://localhost:12703")
  10.  
  11. -- useful methods
  12.  
  13. --function confirm()
  14. --    ws.send("t")
  15. --end
  16.  
  17. --function aborted()
  18. --    ws.send("f")
  19. --end
  20.  
  21. function up()
  22.     if turtle.up() then
  23.         y = y + 1
  24.         --confirm()
  25.     else
  26.         --aborted()
  27.     end
  28. end
  29.  
  30. function down()
  31.     if turtle.down() then
  32.         y = y - 1
  33.         --confirm()
  34.     else
  35.         --aborted()
  36.     end
  37. end
  38.  
  39. function normalized(int)
  40.     local t = int
  41.     while (t < 0) do
  42.         t = t + 4
  43.     end
  44.     while(t > 3) do
  45.         t = t - 4
  46.     end
  47.     return r - int
  48. end
  49.  
  50. function rotate(nr)
  51.     local norm = normalized(nr)
  52.     while nr ~= 0 do
  53.         if nr > 0 then
  54.             nr = nr - 1
  55.             r = r - 1
  56.             turtle.turnLeft()
  57.         else
  58.             nr = nr + 1
  59.             r = r + 1
  60.             turtle.turnRight()
  61.         end
  62.     end
  63. end
  64.  
  65. -- actual turtle loop
  66. up()
  67. down()
  68. rotate(2)
  69. rotate(5)
  70. rotate(3)
  71. rotate(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement