Advertisement
Wired2coffee

Turtle Coordinates Saver

Feb 27th, 2012
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.21 KB | None | 0 0
  1. function back()
  2. turnLeft()
  3. turnLeft()
  4. forward()
  5. end
  6. function forward()
  7. file = io.open("tortoise/tortoiseDir","r")
  8. direction = file:read()
  9. file:close()
  10. file = io.open("tortoise/tortoiseX","r")
  11. x = file:read()
  12. file:close()
  13. file = io.open("tortoise/tortoiseY","r")
  14. y = file:read()
  15. file:close()
  16. file = io.open("tortoise/tortoiseZ","r")
  17. z = file:read()
  18. file:close()
  19. lawl = turtle.forward()
  20. if lawl == true then
  21. if direction == "north" then
  22. shell.run("rm","tortoise/tortoiseZ")
  23. file = io.open("tortoise/tortoiseZ","w")
  24. z = tonumber(z)
  25. file:write(z-1)
  26. file:close()
  27. end
  28. if direction == "west" then
  29. shell.run("rm","tortoise/tortoiseX")
  30. file = io.open("tortoise/tortoiseX","w")
  31. x = tonumber(x)
  32. file:write(x-1)
  33. file:close()
  34. end
  35. if direction == "south" then
  36. shell.run("rm","tortoise/tortoiseZ")
  37. file = io.open("tortoise/tortoiseZ","w")
  38. z = tonumber(z)
  39. file:write(z+1)
  40. file:close()
  41. end
  42. if direction == "east" then
  43. shell.run("rm","tortoise/tortoiseX")
  44. file = io.open("tortoise/tortoiseX","w")
  45. x = tonumber(x)
  46. file:write(x+1)
  47. file:close()
  48. end
  49. end
  50. end
  51. function getXYZD()
  52. file = io.open("tortoise/tortoiseDir","r")
  53. direction = file:read()
  54. file:close()
  55. file = io.open("tortoise/tortoiseX","r")
  56. x = tonumber(file:read())
  57. file:close()
  58. file = io.open("tortoise/tortoiseY","r")
  59. y = tonumber(file:read())
  60. file:close()
  61. file = io.open("tortoise/tortoiseZ","r")
  62. z = tonumber(file:read())
  63. file:close()
  64. return x,y,z,direction
  65. end
  66. function printXYZD()
  67. file = io.open("tortoise/tortoiseDir","r")
  68. direction = file:read()
  69. file:close()
  70. file = io.open("tortoise/tortoiseX","r")
  71. x = tonumber(file:read())
  72. file:close()
  73. file = io.open("tortoise/tortoiseY","r")
  74. y = tonumber(file:read())
  75. file:close()
  76. file = io.open("tortoise/tortoiseZ","r")
  77. z = tonumber(file:read())
  78. file:close()
  79. print(x.." "..y.." "..z.." "..direction)
  80. end
  81. function up()
  82. file = io.open("tortoise/tortoiseY","r")
  83. y = file:read()
  84. y = tonumber(y)
  85. file:close()
  86. lawl = turtle.up()
  87. if lawl == true then
  88. shell.run("rm","tortoise/tortoiseY")
  89. file = io.open("tortoise/tortoiseY","w")
  90. if y < 126 and y >= 1 then
  91. file:write(y+1)
  92. else
  93. file:write(y)
  94. end
  95. file:close()
  96. end
  97. end
  98. function turnLeft()
  99. file = io.open("tortoise/tortoiseDir","r")
  100. direction = file:read()
  101. file:close()
  102. shell.run("rm","tortoise/tortoiseDir","r")
  103. turtle.turnLeft()
  104. file = io.open("tortoise/tortoiseDir","w")
  105. if direction == "west" then
  106. file:write("south")
  107. end
  108. if direction == "east" then
  109. file:write("north")
  110. end
  111. if direction == "south" then
  112. file:write("east")
  113. end
  114. if direction == "north" then
  115. file:write("west")
  116. end
  117. file:close()
  118. end
  119. function turnRight()
  120. file = io.open("tortoise/tortoiseDir","r")
  121. direction = file:read()
  122. file:close()
  123. shell.run("rm","tortoise/tortoiseDir","r")
  124. turtle.turnRight()
  125. file = io.open("tortoise/tortoiseDir","w")
  126. if direction == "west" then
  127. file:write("north")
  128. end
  129. if direction == "east" then
  130. file:write("south")
  131. end
  132. if direction == "south" then
  133. file:write("west")
  134. end
  135. if direction == "north" then
  136. file:write("east")
  137. end
  138. file:close()
  139. end
  140. function setUp()
  141. shell.run("mkdir","tortoise")
  142. shell.run("clear")
  143. print("What direction is your turtle currently facing? (lower case)")
  144. out = read()
  145. file = io.open("tortoise/tortoiseDir","w")
  146. file:write(out)
  147. file:close()
  148. print("Current X Coord?")
  149. out = read()
  150. file = io.open("tortoise/tortoiseX","w")
  151. file:write(out)
  152. file:close()
  153. print("Current Z Coord?")
  154. out = read()
  155. file = io.open("tortoise/tortoiseZ","w")
  156. file:write(out)
  157. file:close()
  158. print("Current Y Coord?")
  159. out = read()
  160. file = io.open("tortoise/tortoiseY","w")
  161. file:write(out)
  162. file:close()
  163. shell.run("clear")
  164. print("Finished")
  165. end
  166. function down()
  167. file = io.open("tortoise/tortoiseY","r")
  168. y = file:read()
  169. y = tonumber(y)
  170. file:close()
  171. lawl = turtle.down()
  172. shell.run("rm","tortoise/tortoiseY")
  173. if lawl == true then
  174. file = io.open("tortoise/tortoiseY","w")
  175. if y <= 126 and y > 1 then
  176. file:write(y-1)
  177. end
  178. else
  179. file = io.open("tortoise/tortoiseY","w")
  180. file:write(y)
  181. end
  182. file:close()
  183. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement