Godleydemon

diggy

Jun 9th, 2013
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.22 KB | None | 0 0
  1. -- Clears a x by y by z area
  2.  
  3. local turtleId
  4. local isWirelessTurtle
  5. local messageOutputFileName
  6.  
  7.  
  8.  
  9. isWirelessTurtle = peripheral.isPresent("right")
  10. if (isWirelessTurtle == true) then
  11.   turtleId = os.getComputerLabel()
  12.   rednet.open("right")
  13. end
  14.  
  15. function writeMessage(message)
  16.     print(message)
  17.  
  18.     -- If this turtle has a modem, then write the message to red net
  19.     if (isWirelessTurtle == true) then
  20.       if (turtleId == nil) then
  21.         rednet.broadcast(message)
  22.       else
  23.         -- Broadcast the message (prefixed with the turtle's id)
  24.         rednet.broadcast("[".. turtleId.."] "..message)
  25.       end
  26.     end
  27.  
  28.     if (messageOutputFileName ~= nil) then
  29.       -- Open file, write message and close file (flush doesn't seem to work!)
  30.       local outputFile = io.open(messageOutputFileName, "a")
  31.       outputFile:write(message)
  32.       outputFile:write("\n")
  33.       outputFile:close()
  34.     end
  35. end
  36.  
  37.  
  38.  
  39.  
  40. function refuel()
  41.         turtle.select(1)
  42.         turtle.refuel(64)
  43. end
  44.  
  45. function clear()
  46.         term.clear()
  47.         term.setCursorPos(1,1)
  48. end
  49.  
  50. function clearLine()
  51.         for i = 1, depth do
  52.                 turtle.dig()
  53.                 turtle.forward()
  54.         end
  55.        
  56.         for i = 1, depth do
  57.                 turtle.back()
  58.         end
  59. end
  60.  
  61. function clearWall()
  62.         for i = 1, height do
  63.                 turtle.digUp()
  64.                 clearLine()
  65.                 turtle.up()
  66.         end
  67.  
  68.         for i = 1, height do
  69.                 turtle.down()
  70.         end
  71. end
  72.  
  73. function clearCube()
  74.         for i = 1, width do
  75.                 clearWall()
  76.                 turtle.turnRight()
  77.                 turtle.dig()
  78.                 turtle.forward()
  79.                 turtle.turnLeft()
  80.         end
  81.  
  82.         turtle.turnLeft()
  83.  
  84.         for i = 1, width+1 do
  85.                 turtle.forward()
  86.         end
  87.  
  88.         turtle.turnRight()
  89. end
  90.                
  91.  
  92.  
  93. term.write("Insert depth: ")
  94. depth = tonumber(read())
  95. print(" ")
  96.  
  97. term.write("Insert width: ")
  98. width = tonumber(read())
  99. print(" ")
  100.  
  101. term.write("Insert height: ")
  102. height = tonumber(read())
  103. print(" ")
  104.  
  105. writeMessage("beginning to clear")
  106.  
  107. refuel()
  108. clearCube()
  109.  
  110. writeMessage("Done Clearing")
Advertisement
Add Comment
Please, Sign In to add comment