Posted 28 July 2013 - 02:05 AM
Hello,
I have been trying off and on for weeks to make a program that does 3x3 Mining Tunnel, Desired Ore Detection, AutoFuel, and Torch Placement and I can't seem to get it to function 100%. I was thinking maybe a fresh pair of eyes will be able to help finish the code. Right now as it stands: Desired Ore Detection does not work, if the turtle runs out of fuel or manages to somehow detect the desired ore it doesnt resume where it left off when refueled or ore removed it restarts the dig function from the beginning causing undesired tunnel shape. As far as I am aware the Torch Placement and the AutoFuel both work correctly.
I have been trying off and on for weeks to make a program that does 3x3 Mining Tunnel, Desired Ore Detection, AutoFuel, and Torch Placement and I can't seem to get it to function 100%. I was thinking maybe a fresh pair of eyes will be able to help finish the code. Right now as it stands: Desired Ore Detection does not work, if the turtle runs out of fuel or manages to somehow detect the desired ore it doesnt resume where it left off when refueled or ore removed it restarts the dig function from the beginning causing undesired tunnel shape. As far as I am aware the Torch Placement and the AutoFuel both work correctly.
function text()
shell.run("clear")
print("Fuel level: ".. turtle.getFuelLevel())
print ""
if turtle.getItemCount(16) == 0 then
print "Warning: NO TORCHES LOADED in SLOT 16"
print ""
end
end
function digCompare()
turtle.select(15)
if turtle.getItemCount(15) == 0 then
print ""
print "DESIRED ORE is MISSING from SLOT 15!"
while turtle.getItemCount(15) == 0 do
sleep(1)
end
end
if turtle.compare() == true then
print ""
print "DESIRED ORE LOCATED!"
print ""
while turtle.compare() == true do
sleep(1)
end
turtle.select(1)
else
dig()
sleep(.6)
end
turtle.select(15)
if turtle.compareUp() == true then
print ""
print "DESIRED ORE LOCATED!"
print ""
while turtle.compareUp() == true do
sleep(1)
end
turtle.select(1)
else
dig()
sleep(.6)
end
end
function dig()
turtle.dig()
turtle.forward()
turtle.turnLeft()
turtle.dig()
turtle.turnRight()
turtle.turnRight()
turtle.dig()
turtle.turnLeft()
turtle.digUp()
turtle.up()
turtle.turnLeft()
turtle.dig()
turtle.turnRight()
turtle.turnRight()
turtle.dig()
turtle.turnLeft()
turtle.digUp()
turtle.up()
turtle.turnLeft()
turtle.dig()
turtle.turnRight()
turtle.turnRight()
turtle.dig()
turtle.turnLeft()
turtle.down()
turtle.down()
sleep(.6)
end
function DesiredOreDetection()
io.write "Turn Desired Ore Detection on? (Y/N): "
s = io.read()
if s == "y" then
if turtle.getItemCount(15) == 0 then
print ""
print "Place DESIRED ORE in SLOT 15."
while turtle.getItemCount(15) == 0 do
sleep(1)
end
end
end
if s ~= "y" then
if s ~= "n" then
print ""
print "Please enter (Y) or (N)"
print ""
DesiredOreDetection()
else
autoFuel()
end
else
autoFuel()
end
end
function autoFuel()
io.write "Turn Automatic Re-Fueling on? (Y/N): "
f = io.read()
if f ~= "y" then
if f ~= "n" then
print ""
print "Please enter (Y) or (N)"
print ""
autoFuel()
else
start()
end
else
start()
end
end
function start()
io.write "Enter length of tunnel: "
d = io.read()
if not tonumber(d) then
print ""
print "Invalid Selection"
print ""
start()
else
d = tonumber(d)
end
if d < 1 then
print ""
print "Invalid Number"
print ""
start()
end
end
function placeTorch()
turtle.turnLeft()
turtle.turnLeft()
turtle.select(16)
turtle.place()
turtle.select(1)
turtle.turnRight()
turtle.turnRight()
end
function addFuel()
print ""
print "Add fuel to continue..."
turtle.select(1)
while turtle.getFuelLevel() == 0 do
turtle.refuel()
sleep(1)
end
print ""
print "Yummy, thank you!"
print ""
end
function fuelCheck()
if turtle.getFuelLevel() == 0 then
if f == "y" then
for i = 1, 16 do
turtle.select(i)
turtle.refuel(1)
if turtle.getFuelLevel() > 0 then
turtle.select(1)
break
end
end
if turtle.getFuelLevel() == 0 then
addFuel()
end
else
addFuel()
end
end
end
t = 8
text()
DesiredOreDetection()
turtle.refuel()
for i = 1, d do
fuelCheck()
turtle.placeDown()
if s == "y" then
digCompare()
else
dig()
end
t = t + 1
if t == 10 then
placeTorch()
t = 0
end
end