Advertisement
Guest User

Quarry Turtle.

a guest
Oct 24th, 2014
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.51 KB | None | 0 0
  1. start = {0, 0, 0, 1} ; Using the syntax as: x, y, z, o
  2. x = start[1]
  3. y = start[2]
  4. z = start[3]
  5. orientation = start[4]
  6. orientations = {"north", "east", "south", "west"}
  7. x_Quarry = x
  8. y_Quarry = y
  9. z_Quarry = z
  10.  
  11. function get_Refuel_Distance()
  12.  
  13. end
  14.  
  15. ; This will use the syntax of turn("left")/turn("right") and returns true
  16. ; However, if other arguments are supplied, then the function will return
  17. ; false.
  18. function turn(direction)
  19.     if (direction == "left" or direction == "right") then
  20.         orientation = orientation - 1
  21.         orientation = orientation % 4
  22.         if direction == "left" then
  23.             orientation = orientation - 1
  24.             turtle.turnLeft()
  25.         else
  26.             orientation = orientation + 1
  27.             turtle.turnRight()
  28.         end
  29.  
  30.         return true
  31.     else
  32.         return false
  33.     end
  34. end
  35.  
  36. ; This will take the arguments of either "forward" or "backward" and then return true if
  37. ; it can move AND a correct argument is supplied.
  38. function move(direction)
  39.     distance = get_Refuel_Distance()
  40.     check_fuel(distance)
  41.  
  42.     if (direction == "forward" or direction == "backward") then
  43.         direction_index_X = {0, -1, 0, 1}
  44.         direction_index_Z = {-1, 0, 1, 0}
  45.         if (direction == "forward") then
  46.             if (turtle.forward()) then
  47.                 x += direction_index_X[orientation]
  48.                 z += direction_index_Z[orientation]
  49.                 return true
  50.             else
  51.                 return false
  52.             end
  53.         else
  54.             if (turtle.back()) then
  55.                 x -= direction_index_X[orientation]
  56.                 z -= direction_index_Z[orientation]
  57.             return true
  58.             else
  59.                 return false
  60.             end
  61.         end
  62.     else
  63.         return false
  64.     end
  65. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement