Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. directions = {"north", "east", "south", "west"}
  2.  
  3. local position = {}
  4. local direction = ""
  5. function init(x, y, z, dir)
  6. position = to_pos(x, y, z)
  7. direction = dir
  8. end
  9.  
  10. function forward()
  11. if turtle.forward() then
  12. forward_increment()
  13. print_pos()
  14. end
  15. end
  16.  
  17. function back()
  18. if turtle.back() then
  19. backward_increment()
  20. print_pos()
  21. end
  22. end
  23.  
  24. function up()
  25. if turtle.up() then
  26. position = {
  27. x = position.x,
  28. y = position.y + 1,
  29. z = position.z
  30. }
  31. end
  32. end
  33.  
  34. function down()
  35. if turtle.down() then
  36. position = {
  37. x = position.x,
  38. y = position.y - 1,
  39. z = position.z
  40. }
  41. end
  42. end
  43.  
  44. function turnLeft()
  45. if turtle.turnLeft() then
  46. if direction == "north" then
  47. direction = "west"
  48. elseif direction == "east" then
  49. direction = "north"
  50. elseif direction == "south" then
  51. direction = "east"
  52. elseif direction == "west" then
  53. direction = "south"
  54. end
  55. end
  56. end
  57.  
  58. function turnRight()
  59. if turtle.turnRight() then
  60. if direction == "north" then
  61. direction = "east"
  62. elseif direction == "east" then
  63. direction = "south"
  64. elseif direction == "south" then
  65. direction = "west"
  66. elseif direction == "west" then
  67. direction = "north"
  68. end
  69. end
  70. end
  71. function forward_increment()
  72. if direction == directions[1] then
  73. position = {
  74. x = position.x,
  75. y = position.y,
  76. z = position.z - 1
  77. }
  78. elseif direction == directions[2] then
  79. position = {
  80. x = position.x + 1,
  81. y = position.y,
  82. z = position.z
  83. }
  84. elseif direction == directions[3] then
  85. position = {
  86. x = position.x,
  87. y = position.y,
  88. z = position.z + 1
  89. }
  90. elseif direction == directions[4] then
  91. position = {
  92. x = position.x - 1,
  93. y = position.y,
  94. z = position.z
  95. }
  96. end
  97. end
  98.  
  99. function backward_increment()
  100. if direction == directions[1] then
  101. position = {
  102. x = position.x,
  103. y = position.y,
  104. z = position.z + 1
  105. }
  106. elseif direction == directions[2] then
  107. position = {
  108. x = position.x - 1,
  109. y = position.y,
  110. z = position.z
  111. }
  112. elseif direction == directions[3] then
  113. position = {
  114. x = position.x,
  115. y = position.y,
  116. z = position.z - 1
  117. }
  118. elseif direction == directions[4] then
  119. position = {
  120. x = position.x + 1,
  121. y = position.y,
  122. z = position.z
  123. }
  124. end
  125. end
  126.  
  127. function to_pos(x1, y1, z1)
  128. return {x=x1, y=y1, z=z1}
  129. end
  130.  
  131. function print_pos()
  132. print("Position: (" .. position.x .. ", " .. position.y .. ", " .. position.z .. ")")
  133. end
  134.  
  135. function goto(position)
  136. -- nothing
  137. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement