Advertisement
jdroid91

checkDirection

Jan 18th, 2024 (edited)
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.83 KB | None | 0 0
  1. local currentDirection = nil
  2.  
  3. function getCurrentDirection()
  4.     local blockStatus, blockData = turtle.inspect()
  5.     if (blockStatus == false)
  6.     then
  7.         local tp1X, tp1Y, tp1Z = gps.locate()
  8.         turtle.forward()
  9.         local tp2X, tp2Y, tp2Z = gps.locate()
  10.         turtle.back()
  11.      
  12.         if (tp1X == tp2X)
  13.         then
  14.             if (tp1Z < tp2Z)
  15.             then
  16.                 currentDirection = "South"
  17.             else
  18.                 currentDirection = "North"
  19.             end
  20.         else
  21.             if (tp1X < tp2X)
  22.             then
  23.                 currentDirection = "East"
  24.             else
  25.                 currentDirection = "West"
  26.             end
  27.         end
  28.     else
  29.         turnLeft()
  30.         getCurrentDirection()
  31.     end
  32. end
  33.  
  34. getCurrentDirection()
  35. print("Direction: "..currentDirection)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement