Advertisement
zaboodable

Turtle Stair

Apr 9th, 2017
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.03 KB | None | 0 0
  1. -- Parameters
  2. local length = 10
  3. local width = 1
  4. local stepHeight = 3
  5. local direction = 1
  6.  
  7. -- Variables
  8. local distance = 0
  9.  
  10. write("Enter Length: ")
  11. length = tonumber(io.read()) or length
  12. print("Length set to " .. length)
  13. print("")
  14.  
  15. write("Enter Width: ")
  16. width = tonumber(io.read()) or width
  17. print("Width set to " .. width)
  18. print("")
  19.  
  20. write("Enter Step Height: ")
  21. stepHeight = tonumber(io.read()) or stepHeight
  22. print("Step Height set to " .. stepHeight)
  23. print("")
  24.  
  25. print("Enter Direction")
  26. write("(0) left, (1) right: ")
  27. local dir = tonumber(io.read()) or direction
  28. local dirString = "none"
  29. if (dir == 0 or dir == 1) then
  30.   direction = dir
  31.   if (dir == 0) then
  32.     dirString = "Left"
  33.   else
  34.     dirString = "Right"
  35.   end
  36. end
  37. print("Direction set to " .. dirString)
  38. print("")
  39.  
  40. -- Functions
  41. function Dig()
  42.   while(turtle.detect()) do
  43.     turtle.dig()
  44.     sleep(0.5)
  45.   end
  46. end
  47.  
  48. function DigUp()
  49.   while(turtle.detectUp()) do
  50.     turtle.digUp()
  51.     sleep(0.5)
  52.   end
  53. end
  54.  
  55. function DigDown()
  56.   while(turtle.detectDown()) do
  57.     turtle.digDown()
  58.     sleep(0.5)
  59.   end
  60. end
  61.  
  62. function StepUp(move)
  63.   DigUp()
  64.   if (move) then
  65.     turtle.up()
  66.   end
  67. end
  68.  
  69. function Step()
  70.   Dig()
  71.   turtle.forward()
  72.   DigDown()
  73.   for i = 1, stepHeight - 1 do
  74.     if (i == stepHeight - 1) then
  75.       StepUp(false)
  76.     else
  77.       StepUp(true)
  78.     end
  79.   end
  80.   for i = 1, stepHeight do
  81.     turtle.down()
  82.   end
  83.   distance = distance + 1
  84. end
  85.  
  86. function StepBack()
  87.   turtle.up()
  88.   turtle.back()
  89. end
  90.  
  91. function TurnStep()
  92.   if (direction == 0) then
  93.     turtle.turnLeft()
  94.   else
  95.     turtle.turnRight()
  96.   end
  97.   Dig()
  98.   turtle.forward()
  99.   if (direction == 0) then
  100.     turtle.turnRight()
  101.   else
  102.     turtle.turnLeft()
  103.   end
  104. end
  105.  
  106. function NextLine()
  107.   TurnStep()  
  108. end
  109.  
  110. -- Main
  111. for w = 1, width do
  112.   for l = 1, length do
  113.     Step()
  114.   end
  115.   for l = 1, length do
  116.     StepBack()
  117.   end
  118.   if (width == 1) then
  119.     break
  120.   else
  121.     if (w == width) then
  122.       break
  123.     else
  124.       NextLine()
  125.     end
  126.   end  
  127. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement