Posted 02 October 2012 - 08:59 PM
Heyas,
I kind of tried combining two different codes to create a branch mining code that will branch mine, as well as return the items to the start, but for some reason it's not working. When I run it, it just comes up with the shell again (after initiating mining sequence), instead of actually initiating the mining sequence. If someone could go through the code and possibly tell me what's wrong/botched about it?
Added: Fuel not needed as I'm running an older version of ComputerCraft.
local collected = 0
local xPos,zPos = 0,0
local xDir,zDir = 0,1
shell.run("clear")
print("Auto Branch Miner")
print("Press Enter to Continue")
null = read()
shell.run("clear")
print("Instructions:")
print("Put Torches in the first slot.")
print("The Mining Turtle will go on as long as the chunk it's in is active.")
print("")
print("Press Enter to Continue")
null = read()
shell.run("clear")
print("Mining…")
local function unload()
print( "Unloading items…" )
for n=2,9 do
unloaded = unloaded + turtle.getItemCount(n)
turtle.select(n)
turtle.drop()
end
collected = 0
turtle.select(1)
end
local function returnSupplies()
local x,y,z,xd,zd = xPos,depth,zPos,xDir,zDir
print( "Returning to surface…" )
goTo( 0,0,0,0,-1 )
unload()
print( "Resuming mining…" )
goTo( x,y,z,xd,zd )
end
local function collect()
local bFull = true
local nTotalItems = 0
for n=1,16 do
local nCount = turtle.getItemCount(n)
if nCount == 0 then
bFull = false
end
nTotalItems = nTotalItems + nCount
end
if nTotalItems > collected then
collected = nTotalItems
if math.fmod(collected + unloaded, 50) == 0 then
print( "Mined "..(collected + unloaded).." items." )
end
end
if bFull then
print( "No empty slots left." )
return false
end
return true
end
function goTo( x, y, z, xd, zd )
while depth > y do
if turtle.up() then
depth = depth - 1
elseif turtle.digUp() or turtle.attackUp() then
collect()
else
sleep( 0.5 )
end
end
if xPos > x then
while xDir ~= -1 do
turnLeft()
end
while xPos > x do
if turtle.forward() then
xPos = xPos - 1
elseif turtle.dig() or turtle.attack() then
collect()
else
sleep( 0.5 )
end
end
elseif xPos < x then
while xDir ~= 1 do
turnLeft()
end
while xPos < x do
if turtle.forward() then
xPos = xPos + 1
elseif turtle.dig() or turtle.attack() then
collect()
else
sleep( 0.5 )
end
end
end
if zPos > z then
while zDir ~= -1 do
turnLeft()
end
while zPos > z do
if turtle.forward() then
zPos = zPos - 1
elseif turtle.dig() or turtle.attack() then
collect()
else
sleep( 0.5 )
end
end
elseif zPos < z then
while zDir ~= 1 do
turnLeft()
end
while zPos < z do
if turtle.forward() then
zPos = zPos + 1
elseif turtle.dig() or turtle.attack() then
collect()
else
sleep( 0.5 )
end
end
end
while depth < y do
if turtle.down() then
depth = depth + 1
elseif turtle.digDown() or turtle.attackDown() then
collect()
else
sleep( 0.5 )
end
end
while zDir ~= zd or xDir ~= xd do
turnLeft()
end
end
function dig()
tdig = "true"
while tdig == "true" do
sleep(0.5)
if turtle.detect() then
tdig = "true"
else
tdig = "false"
end
turtle.dig()
end
end
function forward()
tforward = "true"
while tforward == "true" do
if turtle.forward() then
tforward = "false"
else
tforward = "true"
end
end
end
function back(amount)
for b = 1,amount do
tback = "true"
while tback == "true" do
if turtle.back() then
tback = "false"
else
turtle.turnRight()
turtle.turnRight()
dig()
turtle.turnRight()
turtle.turnRight()
tback = "true"
end
end
end
end
function digUp()
turtle.digUp()
end
function move(amount)
for m = 1,amount do
digUp()
dig()
forward()
end
end
direction = "right"
move(2)
if direction == "right" then
turtle.turnRight()
else
turtle.turnLeft()
end
move(1)
for
c=1,2 do
turtle.digUp()
dig()
forward()
turtle.digUp()
back(1)
turtle.select(1)
turtle.placeUp()
turtle.dig()
forward()
move(13)
end
turtle.select(1)
turtle.digUp()
turtle.placeUp()
back(29)
if direction == "right" then
turtle.turnLeft()
direction = "left"
else
turtle.turnRight()
direction = "right"
end
end
I kind of tried combining two different codes to create a branch mining code that will branch mine, as well as return the items to the start, but for some reason it's not working. When I run it, it just comes up with the shell again (after initiating mining sequence), instead of actually initiating the mining sequence. If someone could go through the code and possibly tell me what's wrong/botched about it?
Added: Fuel not needed as I'm running an older version of ComputerCraft.
Spoiler
local unloaded = 0local collected = 0
local xPos,zPos = 0,0
local xDir,zDir = 0,1
shell.run("clear")
print("Auto Branch Miner")
print("Press Enter to Continue")
null = read()
shell.run("clear")
print("Instructions:")
print("Put Torches in the first slot.")
print("The Mining Turtle will go on as long as the chunk it's in is active.")
print("")
print("Press Enter to Continue")
null = read()
shell.run("clear")
print("Mining…")
local function unload()
print( "Unloading items…" )
for n=2,9 do
unloaded = unloaded + turtle.getItemCount(n)
turtle.select(n)
turtle.drop()
end
collected = 0
turtle.select(1)
end
local function returnSupplies()
local x,y,z,xd,zd = xPos,depth,zPos,xDir,zDir
print( "Returning to surface…" )
goTo( 0,0,0,0,-1 )
unload()
print( "Resuming mining…" )
goTo( x,y,z,xd,zd )
end
local function collect()
local bFull = true
local nTotalItems = 0
for n=1,16 do
local nCount = turtle.getItemCount(n)
if nCount == 0 then
bFull = false
end
nTotalItems = nTotalItems + nCount
end
if nTotalItems > collected then
collected = nTotalItems
if math.fmod(collected + unloaded, 50) == 0 then
print( "Mined "..(collected + unloaded).." items." )
end
end
if bFull then
print( "No empty slots left." )
return false
end
return true
end
function goTo( x, y, z, xd, zd )
while depth > y do
if turtle.up() then
depth = depth - 1
elseif turtle.digUp() or turtle.attackUp() then
collect()
else
sleep( 0.5 )
end
end
if xPos > x then
while xDir ~= -1 do
turnLeft()
end
while xPos > x do
if turtle.forward() then
xPos = xPos - 1
elseif turtle.dig() or turtle.attack() then
collect()
else
sleep( 0.5 )
end
end
elseif xPos < x then
while xDir ~= 1 do
turnLeft()
end
while xPos < x do
if turtle.forward() then
xPos = xPos + 1
elseif turtle.dig() or turtle.attack() then
collect()
else
sleep( 0.5 )
end
end
end
if zPos > z then
while zDir ~= -1 do
turnLeft()
end
while zPos > z do
if turtle.forward() then
zPos = zPos - 1
elseif turtle.dig() or turtle.attack() then
collect()
else
sleep( 0.5 )
end
end
elseif zPos < z then
while zDir ~= 1 do
turnLeft()
end
while zPos < z do
if turtle.forward() then
zPos = zPos + 1
elseif turtle.dig() or turtle.attack() then
collect()
else
sleep( 0.5 )
end
end
end
while depth < y do
if turtle.down() then
depth = depth + 1
elseif turtle.digDown() or turtle.attackDown() then
collect()
else
sleep( 0.5 )
end
end
while zDir ~= zd or xDir ~= xd do
turnLeft()
end
end
function dig()
tdig = "true"
while tdig == "true" do
sleep(0.5)
if turtle.detect() then
tdig = "true"
else
tdig = "false"
end
turtle.dig()
end
end
function forward()
tforward = "true"
while tforward == "true" do
if turtle.forward() then
tforward = "false"
else
tforward = "true"
end
end
end
function back(amount)
for b = 1,amount do
tback = "true"
while tback == "true" do
if turtle.back() then
tback = "false"
else
turtle.turnRight()
turtle.turnRight()
dig()
turtle.turnRight()
turtle.turnRight()
tback = "true"
end
end
end
end
function digUp()
turtle.digUp()
end
function move(amount)
for m = 1,amount do
digUp()
dig()
forward()
end
end
direction = "right"
move(2)
if direction == "right" then
turtle.turnRight()
else
turtle.turnLeft()
end
move(1)
for
c=1,2 do
turtle.digUp()
dig()
forward()
turtle.digUp()
back(1)
turtle.select(1)
turtle.placeUp()
turtle.dig()
forward()
move(13)
end
turtle.select(1)
turtle.digUp()
turtle.placeUp()
back(29)
if direction == "right" then
turtle.turnLeft()
direction = "left"
else
turtle.turnRight()
direction = "right"
end
end