Guest User

clearArea

a guest
Jun 19th, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.00 KB | None | 0 0
  1. --Clear Area Program--
  2.      
  3. home = "top"
  4. atX = 0
  5. atZ = 0
  6. atY = 0
  7. args = {...}
  8.      
  9.     --Insert Config Size Code here
  10. length = 2
  11. width = 2
  12. height = 1
  13.      
  14. -- Basic movement functions to prevent sand/gravel from getting in the way
  15. function dig()
  16.   while turtle.detect() do
  17.     turtle.dig()
  18.     sleep(.1)
  19.   end
  20. end
  21.      
  22. function digUp()
  23.   while turtle.detect() do
  24.     turtle.digUp()
  25.     sleep(.1)
  26.   end
  27. end
  28.      
  29. function forward()
  30.   while not turtle.forward() do
  31.     turtle.dig()
  32.     sleep(.1)
  33.   end
  34. end
  35.      
  36. function line(distance) -- Turtle mines in straight line based on length
  37.   local x=0
  38.   while x<distance do
  39.     forward()
  40.     x=x+1
  41.   end
  42. end
  43.  
  44. --End of movement functions
  45.      
  46. function continue() -- Figures out turtle's top/bottom location and moves him to new column in loop if he is supposed to
  47.   if home == "top" then
  48.     turtle.turnRight()
  49.     forward()
  50.     turtle.turnRight()
  51.     atX = atX +1
  52.      
  53.   elseif home == "bottom" then
  54.     turtle.turnLeft()
  55.     forward()
  56.     turtle.turnLeft()
  57.     atX = atX +1
  58.    
  59.   else
  60.     print("Neither top nor bottom were part of gohome counted here...ERROR!")
  61.   end
  62. end
  63.      
  64. function gohome() -- On completion of layer, returns to starting position.
  65.   print("Coming home!")
  66.   if home == "top" then
  67.     turtle.turnLeft()
  68.     turtle.turnLeft()
  69.     line(length-1)
  70.     turtle.turnRight()
  71.     line(width-1)
  72.   elseif home == "bottom" then
  73.     turtle.turnRight()
  74.     line(width-1)
  75.   else
  76.     print("ERROR with HOME RETURN!")
  77.   end
  78.   turtle.turnRight()
  79. end
  80.      
  81. function init()
  82.   print("Clearing area...")
  83.   forward()
  84.   local x=1
  85.   local y=0
  86.  
  87.   while y ~= height do  
  88.     x = 0
  89.     while x ~= width do
  90.       line(length-1)
  91.       continue()
  92.       if home == "top" then
  93.         home = "bottom"
  94.       elseif home == "bottom" then
  95.         home = "top"
  96.       end
  97.       x=x+1
  98.     end
  99.   --  gohome()
  100.     y=y+1
  101.     if y ~= height then
  102.       digUp()
  103.       turtle.up()
  104.     end  
  105.   end
  106. end
  107.      
  108. init()
Advertisement
Add Comment
Please, Sign In to add comment