Advertisement
Ollie_Armitage

Move

Aug 17th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.18 KB | None | 0 0
  1. -- Move on the X axis i.e. East / West
  2.  
  3. function move_X(number)
  4.  
  5.     if(number <= 0) then
  6.         turn("W")
  7.         return true
  8.  
  9.     elseif(number >= 0) then
  10.         turn("E")
  11.         return true
  12.    
  13.     else
  14.         return true
  15.     end
  16. end
  17.  
  18. -- Move on the Y axis i.e. Up / Down
  19.  
  20. function move_Y(number)
  21.  
  22.     return true
  23. end
  24.  
  25. -- Move on the Z axis i.e. North / South
  26.  
  27. function move_Z(number)
  28.     if(number <= 0) then
  29.         turn("S")
  30.         return true
  31.  
  32.     elseif(number >= 0) then
  33.         turn("N")
  34.         return true
  35.    
  36.     else
  37.         return true
  38.     end
  39.     return true
  40. end
  41.  
  42. function turn(newDirection)
  43.  
  44.     A = {["N"] = {["N"] = 0, ["E"] = 1, ["S"] = 2, ["W"] = 3},
  45.          ["E"] = {["N"] = 3, ["E"] = 0, ["S"] = 1, ["W"] = 2},
  46.          ["S"] = {["N"] = 2, ["E"] = 3, ["S"] = 0, ["W"] = 1},
  47.          ["W"] = {["N"] = 1, ["E"] = 2, ["S"] = 3, ["W"] = 0}
  48.     }
  49.  
  50.     currentDirection = getFacing()
  51.  
  52.     if(A[currentDirection][newDirection] == 3) then turtle.turnLeft()
  53.     else
  54.         for 1, A[currentDirection][newDirection] do
  55.             if(A[currentDirection][newDirection]) == 3 then turtle.turnRight() end
  56.         end
  57.     end
  58. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement