Posted 26 February 2013 - 02:02 PM
[Question] my turtles can't deal with gravel
Well i'm trying to write a program for turtles to mine 3 tall 1 wide shafts with 2 blocks in between them, which i can input the lenght(right now i have preset it to 50) and the way it works is it checks for blocks then digs them if there are any then moves(checks up, down and front and mines in that order) then when its done it comes all the way back to where it started but when there is gravel in the way it dig one less row for each row of gravel it comes across and then it goes back to far, i've tried what i could to fix this but i can't get the turtle to dig the shaft and come back properly i would like to hear suggestions on what i could do to fix this, here is the code i wrote:
Well i'm trying to write a program for turtles to mine 3 tall 1 wide shafts with 2 blocks in between them, which i can input the lenght(right now i have preset it to 50) and the way it works is it checks for blocks then digs them if there are any then moves(checks up, down and front and mines in that order) then when its done it comes all the way back to where it started but when there is gravel in the way it dig one less row for each row of gravel it comes across and then it goes back to far, i've tried what i could to fix this but i can't get the turtle to dig the shaft and come back properly i would like to hear suggestions on what i could do to fix this, here is the code i wrote:
--input screen
shell.run('clear')
print("------------------------------")
print("How far do you want me to dig?")
print("------------------------------")
--variables, the 50 is temporary
local x = 50 --io.read()
local i = 0
--functions
local function checkfuel()
if turtle.getFuelLevel() < 5 then
turtle.select(1)
turtle.refuel(1)
turtle.select(1)
end
end
local function minerow()
for i=0,x do
print("Shaft is "..tostring(i).." blocks long.")
while turtle.detectUp() == true do
turtle.digUp()
end
if turtle.detectDown() == true then
turtle.digDown()
end
while turtle.detect() == true do
turtle.dig()
end
if turtle.detect() == false then
turtle.forward()
else
while turtle.detect() == true do
turtle.dig()
end
turtle.forward()
end
end
end
local function comeback()
turtle.turnRight()
turtle.turnRight()
for i=0,x do
while turtle.detect() == true do
turtle.dig()
end
if turtle.detect() == false then
turtle.forward()
else
while turtle.detect() == true do
turtle.dig()
end
turtle.forward()
end
end
end
local function nextpos()
turtle.turnRight()
checkfuel()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.turnRight()
end
minerow()
comeback()
nextpos()