This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Kianon's profile picture

my tunnel digger

Started by Kianon, 14 December 2012 - 03:44 PM
Kianon #1
Posted 14 December 2012 - 04:44 PM
I made a program that digs down a staircase of thirty blocks then starts digging forward. when it hits an empty space it places a block underneath while continuing to mine. it was quite simple to make but it took a while.


turtle.refuel(64)
turtle.select(2)
local x = 0
local y = 1
for i=1, 30 do
  turtle.digDown()
  turtle.dig()
  turtle.down()
  x = x + 1
  turtle.dig()
  turtle.forward()
  x = x + 1
end
while true do
  while turtle.detectDown() do
	turtle.dig()
	turtle.forward()
	x = x + 1
	turtle.digUp()
	if x==6144
	  then turtle.refuel(64)
	  y = y + 1
	  turtle.select(y)
	end
  end
  turtle.select(16)
  while not turtle.detectDown() do
	turtle.placeDown()
	turtle.dig()
	turtle.digUp()
	turtle.forward()
	x = x + 1
end
turtle.digUp()
end
Ulthean #2
Posted 14 December 2012 - 09:46 PM
I made some slight modifications to the code (start it of with a stack of blocks in slot 1 and fuel in slot 2 (optional: you can add fuel in slots 3-16 aswell))
  • Refueling once the program is running should work now
  • (in your program, if the turtle replaced a block below it would select slot 16 and the next time it refuels will try to refuel from slot 16)
  • Accepts any kind/amount of fuel, not only full stacks of peat/coal
  • Reduced the code
Depending on what you are trying to achieve with the code this are features you might want to add:
  • Gravelproofing the code
  • What if the turtle runs out of fuel during the building of the staircase (unlikely if you feed it enough fuel at once, but possible)
  • Allowing the user to choose how long the staircase and tunnel should be without changing the code (prompt or command-line parameters)
  • Better management of the blocks to place (after the first stack runs out it will place random blocks

turtle.select(2)
turtle.refuel()
local fuelSlot = 3
for i=1, 30 do
  turtle.digDown()
  turtle.dig()
  turtle.down()
  turtle.dig()
  turtle.forward()
end
while true do
-- If needed: place a block below
  if not turtle.detectDown() then
	turtle.select(1)
	turtle.placeDown()
  end
-- If needed: refuel the turtle
  if turtle.getFuelLevel()==0 then
	turtle.select(fuelSlot)
	turtle.refuel()
	fuelSlot = fuelSlot + 1
  end
-- Basic operation
  turtle.dig()
  turtle.forward()
  turtle.digUp()
end