Posted 29 December 2012 - 02:20 PM
Hello,
I am posting because I have written a script which a turtle mines a 2x1 strip mine for a user defined length, places torches every 10 blocks and returns when he is finished. All is well apart from I have one problem. When the turtle comes up against some gravel, he mines it fine, however when it comes to placing the next torch he places it prematurely and doesnt move forward the correct number of blocks after her comes up against gravel. When it comes to the turtle moving back down the mine to his starting position, he will stop further back than where he started because he didnt move forward enough after he encountered gravel. I have included my code below, if you know a way to improve it and solve this problem, I will be eternally frateful.
Thanks for any help,
Luke.
I am posting because I have written a script which a turtle mines a 2x1 strip mine for a user defined length, places torches every 10 blocks and returns when he is finished. All is well apart from I have one problem. When the turtle comes up against some gravel, he mines it fine, however when it comes to placing the next torch he places it prematurely and doesnt move forward the correct number of blocks after her comes up against gravel. When it comes to the turtle moving back down the mine to his starting position, he will stop further back than where he started because he didnt move forward enough after he encountered gravel. I have included my code below, if you know a way to improve it and solve this problem, I will be eternally frateful.
Thanks for any help,
Luke.
-- Strip mining turtle program.
-- Luke *********, Ryszard ********. 29/12/12
--[[fuel must be placed in slot 15,
torches must be placed in slot 16.]]
-- Create the function for refueling
function checkFuel()
if turtle.getFuelLevel() <= 10 then
if turtle.getItemCount(15) == 0 then
print("Out of fuel.")
exit()
else
turtle.select(15)
turtle.refuel(1)
turtle.select(1)
end --if
end --if
end --checkFuel()
-- Create the turnAround function
function turnAround()
turtle.turnRight()
turtle.turnRight()
end --turnAround()
-- Digs the tunnel for the given length
function tunnel(givenLength)
local torchDistance = 0
for index = 1,givenLength do
if turtle.detect() then
repeat
turtle.dig()
sleep(0.25)
until turtle.detect() == false
else
turtle.forward()
end --if
torchDistance = torchDistance + 1
if turtle.detectUp() then
repeat
turtle.digUp()
sleep(0.25)
until turtle.detectUp() == false
end --if
-- attempts to place a block below
turtle.select(1)
turtle.placeDown()
-- Places a torch every 10 blocks
if torchDistance == 10 then
print("Placing torch...")
turtle.select(16)
turnAround()
turtle.place()
turnAround()
torchDistance = 0
checkFuel()
end --if
end --for
-- Sends the turtle back to the start
turtle.up()
turnAround()
for index = 1,givenLength do
checkFuel()
if not turtle.detect() then
turtle.forward()
else
repeat
turtle.dig()
turtle.sleep(0.25)
until turtle.detect() == false
turtle.forward()
end --if
end --for
turtle.down()
turnAround()
end --tunnel()
-- Main script
print("Input tunnel length:")
local length = read()
print("starting excavation...")
checkFuel()
tunnel(length)
print("The tunnel has been excavated!")