DrFair

Enchant Turtle

Apr 5th, 2013
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. x,y,z = 0,0
  2. dir = { [0]="-Y", [1]="+X", [2]="+Y", [3]="-X", [4]="-Y", [4]="+X" }
  3. nDir = 1
  4. cID = 60
  5. rednet.open("right")
  6. sr = peripheral.wrap("left")
  7.  
  8. function send(msg)
  9. rednet.send(cID,msg)
  10. end
  11.  
  12. function goDirFor(bool)
  13. if bool then
  14. if dir[nDir] == "+X" then x = x + 1 elseif
  15. dir[nDir] == "-X" then x = x - 1 elseif
  16. dir[nDir] == "+Y" then y = y + 1 elseif
  17. dir[nDir] == "-Y" then y = y - 1 end
  18. else
  19. if dir[nDir] == "+X" then x = x - 1 elseif
  20. dir[nDir] == "-X" then x = x + 1 elseif
  21. dir[nDir] == "+Y" then y = y - 1 elseif
  22. dir[nDir] == "-Y" then y = y + 1 end
  23. end
  24. end
  25.  
  26. function goFor()
  27. if turtle.forward() then
  28. goDirFor(true)
  29. return true
  30. else
  31. return false
  32. end
  33. end
  34.  
  35. function goBack()
  36. if turtle.back() then
  37. goDirFor(false)
  38. return true
  39. else
  40. return false
  41. end
  42. end
  43.  
  44. function goUp()
  45. return turtle.up()
  46. end
  47.  
  48. function goDown()
  49. return turtle.down()
  50. end
  51.  
  52. function turnRight()
  53. turtle.turnRight()
  54. if nDir < 4 then
  55. nDir = nDir + 1
  56. else
  57. nDir = 1
  58. end
  59. end
  60.  
  61. function turnLeft()
  62. turtle.turnLeft()
  63. if nDir > 1 then
  64. nDir = nDir - 1
  65. else
  66. nDir = 4
  67. end
  68. end
  69.  
  70. function turnTo(str)
  71. while dir[nDir] ~= str do
  72. if dir[nDir+1] == str then
  73. turnRight()
  74. elseif dir[nDir-1] == str then
  75. turnLeft()
  76. else
  77. turnRight()
  78. end
  79. end
  80. end
  81.  
  82. function goTo(dx,dy)
  83. if x < dx then
  84. turnTo("+X")
  85. else
  86. turnTo("-X")
  87. end
  88. while x ~= dx do
  89. goFor()
  90. end
  91. if y < dy then
  92. turnTo("+Y")
  93. else
  94. turnTo("-Y")
  95. end
  96. while y ~= dy do
  97. goFor()
  98. end
  99. turnTo("+X")
  100. end
  101.  
  102. function readSign()
  103. return sr.readUp()
  104. end
  105.  
  106. function getItem()
  107. turnLeft()
  108. goFor()
  109. turtle.select(15)
  110. turtle.suckUp()
  111. turtle.select(16)
  112. turtle.suckUp()
  113. goFor()
  114. goUp()
  115. goUp()
  116. goBack()
  117. if turtle.getItemCount(16) == 1 then
  118. turtle.dropDown()
  119. else
  120. turtle.dropDown()
  121. turtle.select(15)
  122. turtle.dropDown()
  123. end
  124. goFor()
  125. goDown()
  126. goDown()
  127. goBack()
  128. goBack()
  129. turnRight()
  130. end
  131.  
  132. getItem()
Advertisement
Add Comment
Please, Sign In to add comment