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

Neew help for Mining Turtle

Started by Zephir, 23 June 2015 - 06:49 PM
Zephir #1
Posted 23 June 2015 - 08:49 PM
Hey,
i have create my own Mining Script. It will Mine a 3x10x100 Tunnel.
Now i have 3 Problems.

1. If the Turtle dig a block an over that was gravel, the Turtle change the Route. How can i fix it?

2. If the Turtle are full, it would drop all items that have no space in the Turtle. Is there a code that the Turtle unload all Items in to a Chest?

3. Is there a Code that the Turtle refuel himself with mined coal?

Thanks for your Help.
Here is my Script:

for Start=1,50 do
turtle.dig()
turtle.forward()
turtle.turnRight()
for Mining=1,9 do
turtle.dig()
turtle.forward()
end
turtle.digUp()
turtle.up()
turtle.turnLeft()
turtle.turnLeft()
for Mining=1,9 do
turtle.dig()
turtle.forward()
end
turtle.digUp()
turtle.up()
turtle.turnRight()
turtle.turnRight()
for Mining=1,9 do
turtle.dig()
turtle.forward()
end
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnLeft()
for Mining=1,9 do
turtle.dig()
turtle.forward()
end
turtle.digDown()
turtle.down()
turtle.turnRight()
turtle.turnRight()
for Mining=1,9 do
turtle.dig()
turtle.forward()
end
turtle.digDown()
turtle.down()
turtle.turnLeft()
turtle.turnLeft()
for Mining=1,9 do
turtle.dig()
turtle.forward()
end
turtle.turnRight()
end
KingofGamesYami #2
Posted 23 June 2015 - 08:58 PM
1. If the Turtle dig a block an over that was gravel, the Turtle change the Route. How can i fix it?
-Sure, instead of using turtle.forward, use this:

local function forward()
  while not turtle.forward() do
    turtle.dig()
  end
  return true
end

2. If the Turtle are full, it would drop all items that have no space in the Turtle. Is there a code that the Turtle unload all Items in to a Chest?
-You can, turtle.drop() will drop an item in front of the turtle. If there is a chest in front of the turtle, it will drop the items into the chest.

3. Is there a Code that the Turtle refuel himself with mined coal?
-turtle.refuel refuels from the currently selected slot. Just do something like this:

local function getFuel()
  for i = 1, 16 do --#iterate through the slots (1-16)
    if turtle.refuel() then --#if there was fuel, we successfully used it
      break --#we don't have to keep looking
    end
  end
end
Zephir #3
Posted 23 June 2015 - 09:09 PM
Ok thank you very much… is there a code like this: if the Turtle are full, go to this Point?
Edited on 23 June 2015 - 07:09 PM
KingofGamesYami #4
Posted 24 June 2015 - 04:27 AM
You could easily check if the turtle is full.


local function isInventoryFilled()
  for i = 1, 16 do --#iterate through the slots
    if turtle.getItemCount( i ) == 0 then --#if one is free
      return false --#inventory is not full
    end
  end
  return true --#if none of the slots are empty, inventory is "full"
end

Note: the turtle could pick up 16 different items, and this would consider the inventory "full", even if there is only 1 of each item in the turtle.

Going to a location is harder, the turtle would have to know where he is and what direction he is facing. Not to mention avoiding or destroying obstructing blocks. There's a fair amount of 'goto' programs/utilities on the forums, you could try one of those.