Advertisement
Guest User

move.lua

a guest
Aug 24th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.94 KB | None | 0 0
  1. args = {...}
  2. cx = args[1]
  3. cy = args[2]
  4. cz = args[3]
  5. x, y, z = gps.locate(3)
  6. local floor = true
  7. print(x, y, z)
  8. print(cx-x, cy-y, cz-z)
  9.  
  10. function getAltitude()
  11.     if floor then
  12.         for i=1, 15 do
  13.             turtle.up()
  14.         end
  15.         floor = false
  16.         testDirection()
  17.     else
  18.         for i=1, 15 do
  19.             turtle.down()
  20.         end
  21.     end
  22. end
  23.  
  24. function checkX()
  25.     x,y,z = gps.locate(3)
  26.     x2 = cx-x
  27.     print(x2)
  28.     if x2 < 0 then
  29.         print("want west [4]")
  30.         face(4)
  31.         print("next step")
  32.     elseif x2 > 0 then
  33.         print("want east [2]")
  34.         face(2)
  35.     end
  36.     print("movin son")
  37.     for i=1, math.abs(x2) do
  38.         turtle.forward()
  39.     end
  40.     checkZ()
  41.    
  42. end
  43.  
  44. function checkY()
  45.     x, y, z = gps.locate()
  46.     y2 = cy - y
  47.    
  48.     for i=1, math.abs(y2) do
  49.         if y2 > 0 then
  50.             turtle.up()
  51.         else
  52.             turtle.down()
  53.         end
  54.     end
  55. end
  56. function checkZ()
  57.     x, y, z = gps.locate(3)
  58.     z2 = cz - z
  59.    
  60.     if z2 < 0 then
  61.         face(1)
  62.     elseif z2 > 0 then
  63.         face(3)
  64.     end
  65.     print("MOVING")
  66.     for i=1, math.abs(z2) do
  67.         turtle.forward()
  68.     end
  69.    
  70.     print("IM HERE!")
  71.     checkY()
  72. end
  73.  
  74. function testDirection()
  75.     turtle.forward()
  76.     x2, y2, z2 = gps.locate(3)
  77.     x3 = x2-x
  78.     y3 = y2-y
  79.     z3 = z2-z
  80.     print(x3, y3, z3)
  81.     if x3 == 1 then
  82.         direction = 2 --east
  83.     elseif x3 == -1 then
  84.         direction = 4 --west
  85.     end
  86.    
  87.     if z3 == 1 then
  88.         direction = 3 --south
  89.     elseif z3 == -1 then
  90.         direction = 1 --north
  91.     end
  92.    
  93.     print("Facing:",direction)
  94.     checkX()
  95. end
  96.  
  97. function face(dir)
  98.     while direction ~= dir do
  99.         turtle.turnRight()
  100.         direction = direction + 1
  101.         if direction == 5 then
  102.             direction = 1
  103.         end
  104.         print(direction)
  105.         sleep(1)
  106.     end
  107.     return
  108. end
  109.  
  110. getAltitude()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement