Advertisement
mathiaas

felling

Dec 15th, 2019 (edited)
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. args = {...}
  2.  
  3. x = 1
  4. y = 1
  5. z = 1
  6. f = 1
  7.  
  8. tasks = {[1] = 3,3,3}
  9. m_table = {
  10. ["fd"] = function()
  11. turtle.forward()
  12. if (f == 1) then
  13. z = z+1
  14. elseif (f == 2) then
  15. x = x+1
  16. elseif (f == 3) then
  17. z = z-1
  18. elseif (f == 4) then
  19. x = x-1
  20. end
  21. end,
  22. ["bk"] = function()
  23. turtle.back()
  24. if (f == 1) then
  25. z = z-1
  26. elseif (f == 2) then
  27. x = x-1
  28. elseif (f == 3) then
  29. z = z+1
  30. elseif (f == 4) then
  31. x = x+1
  32. end
  33. end,
  34. ["rt"] = function()
  35. turtle.turnRight()
  36. if (f < 4) then
  37. f = f+1
  38. else
  39. f = 1
  40. end
  41. end,
  42. ["lt"] = function()
  43. turtle.turnLeft()
  44. if (f > 1) then
  45. f = f-1
  46. else
  47. f = 4
  48. end
  49. end,
  50. ["up"] = function()
  51. turtle.up()
  52. y = y + 1
  53. end,
  54. ["dn"] = function()
  55. turtle.down()
  56. y = y - 1
  57. end
  58.  
  59. }
  60.  
  61. function move(direction)
  62. local _move = m_table[direction]
  63. if (_move) then
  64. _move()
  65. end
  66. end
  67.  
  68. function moveCoords(_x,_y,_z)
  69. if (y < _y) then
  70. repeat
  71. move("up")
  72. until(y == _y)
  73. else
  74. repeat
  75. move("dn")
  76. until(y == _y)
  77. end
  78. repeat
  79. move("rt")
  80. until(f == 2)
  81. if (x < _x) then
  82. repeat
  83. move("fd")
  84. until(x == _x)
  85. else
  86. repeat
  87. move("bk")
  88. until(x == _x)
  89. end
  90.  
  91. repeat
  92. move("lt")
  93. until(f == 1)
  94.  
  95. if (z < _z) then
  96. repeat
  97. move("fd")
  98. until(z == _z)
  99. else
  100. repeat
  101. move("bk")
  102. until(z == _z)
  103. end
  104. end
  105.  
  106. moveCoords(tasks[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement