Advertisement
montana_1

Get Heading

Oct 20th, 2014
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getHeading()
  2.     if(turtle.getFuelLevel() < 2) then
  3.         error("Insufficient fuel")
  4.     end
  5.     local start = vector.new(gps.locate())
  6.     while(turtle.detect()) do
  7.         turtle.dig()
  8.     end
  9.     turtle.forward()
  10.     local current = vector.new(gps.locate())
  11.     turtle.back()
  12.     if(start.z - current.z > 0) then
  13.         heading = 'N'
  14.     elseif (start.z - current.z < 0) then
  15.         heading = 'S'
  16.     end
  17.     if(start.x - current.x > 0) then
  18.         heading = 'W'
  19.     elseif (start.x - current.x < 0) then
  20.         heading = 'E'
  21.     end
  22.         return heading
  23. end
  24.  
  25.  
  26.  
  27. print (getHeading())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement