thorax232

ComputerCraft Caliper/Fill

Jun 22nd, 2014
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.42 KB | None | 0 0
  1. local distance = 0
  2. local length, width
  3.  
  4. --[[Movement/Dig Functions]]--
  5.  
  6. function checkBelow() -- Replace block below with slot 1
  7.     turtle.select(1)
  8.     if turtle.compareDown() == false then
  9.         turtle.digDown()
  10.         turtle.place()
  11.     end
  12. end
  13.  
  14. function digFor() -- Dig forward
  15.     while turtle.detect() do
  16.         turtle.dig()
  17.     end
  18. end
  19.  
  20. function back(n)
  21.     for i=1,n do
  22.         turtle.back()
  23.     end
  24. end
  25.  
  26. --[[Caliper Functions]]--
  27.  
  28. function caliper()
  29.     while turtle.detect() == false do
  30.         turtle.forward()
  31.         distance = distance + 1
  32.     end
  33.     back(distance)
  34.     print("Distance is: ")
  35.     print(distance)
  36.     distance = 0
  37. end
  38.  
  39. --[[Fill Functions]]--
  40.  
  41. function fill()
  42.     lengthOne()
  43.     checkBelow()
  44.     turtle.turnLeft()
  45.     spiralIn()
  46. end
  47.  
  48. function lengthOne()
  49.     for i=1,length-1 do
  50.         checkBelow()
  51.         digFor()
  52.         turtle.forward()
  53.     end
  54. end
  55.  
  56. function spiralIn()
  57.     while length - 1 > 0 do
  58.         for i=1,2 do -- Dig sides of same length twice
  59.             for j=1,length-1 do -- Dig forward and check
  60.                 digFor()
  61.                 turtle.forward()
  62.                 checkBelow()
  63.             end
  64.             turtle.turnLeft() -- Turn upon completion of row
  65.         end
  66.         length = length - 1 -- Decrease side length every two rows
  67.     end
  68. end
  69.  
  70. --[[Main]]--
  71.  
  72. print("Caliper or Fill? (c or f)")
  73. local choice = read()
  74.  
  75. if choice == "c" then
  76.     caliper()
  77. end
  78. if choice == "f" then
  79.     print("How far forward? (length)")
  80.     length = tonumber(read())
  81.     print("How far left? (width)")
  82.     width = tonumber(read())
  83.     fill()
  84. end
Advertisement
Add Comment
Please, Sign In to add comment