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

Need Help on Hole Digger

Started by NiteShad0w, 28 January 2013 - 07:47 PM
NiteShad0w #1
Posted 28 January 2013 - 08:47 PM

local function checkFuel()
  if turtle.getFuelLevel() < 40 then
    turtle.select(1)
    turtle.refuel(1)
  end
end

local function dig()
  turtle.digDown()
  turtle.down()
end

local function mine()
  turtle.dig()
  turtle.forward()
  checkFuel()
  turtle.turnRight()
  turtle.dig()
  turtle.turnLeft()
  turtle.dig()
  turtle.forward()
  checkFuel()
  turtle.turnRight()
  turtle.dig()
  turtle.forward()
  checkFuel()
  turtle.dig()
  turtle.forward()
  checkFuel()
  turtle.turnRight()
  turtle.dig()
  turtle.forward()
  checkFuel()
  turtle.dig()
  turtle.forward()
  turtle.turnRight()
  checkFuel()
  turtle.dig()
  turtle.forward()
  checkFuel()
  turtle.forward()
  turtle.turnRight()
end

local function up()
  while turtle.detectUp() == false do
    turtle.up()
    checkFuel()
  end
end

local function select()
  turtle.select(2)
  turtle.dropUp()
  turtle.select(3)
  turtle.dropUp()
  turtle.select(4)
  turtle.dropUp()
  turtle.select(5)
  turtle.dropUp()
  turtle.select(6)
  turtle.dropUp()
  turtle.select(7)
  turtle.dropUp()
  turtle.select(8)
  turtle.dropUp()
  turtle.select(9)
  turtle.dropUp()
  turtle.select(10)
  turtle.dropUp()
  turtle.select(11)
  turtle.dropUp()
  turtle.select(12)
  turtle.dropUp()
  turtle.select(13)
  turtle.dropUp()
  turtle.select(14)
  turtle.dropUp()
  turtle.select(15)
  turtle.dropUp()
  turtle.select(16)
  turtle.dropUp()
  turtle.select(1)
end

local function down()
  while turtle.detectDown() == false or turtle.detect() == false do
    turtle.down()
    checkFuel()
  end
end

local function drop()
  if turtle.getItemCount(16) >= 1 then
    up()
    select()
    down()
  end
end

while true do
  dig()
  mine()
  drop()
end

This was my first program that has been modified 2 or 3 times to suit use in survival mode. The only thing that doesn't work is that when it comes back up to drop off items, it keeps trying to go down even when it reaches where it left off. It won't mine.



local function down()
  while turtle.detectDown() == false or turtle.detect() == false do
    turtle.down()
    checkFuel()
  end
end

This is the code that makes it go down. The problem with it is that when the turtle went all the way back down to where it left off then it wouldn't continue mining because when it reaches the bottom the turtle.detect() is still false. I put the turtle.detect() because I wanted to make sure it would stop in case there was a cave that it dug into earlier. Now I realize that the turtle.detect() is useless. Is there a way to make sure that it would continue where it left off even though it dug into a cave earlier. Also I'm still a beginner so any other suggestions on my first code would be really appreciated. :lol:/>/> And thanks for any help :lol:/>/>
Lyqyd #2
Posted 29 January 2013 - 04:25 AM
Split to new topic.