Posted 12 December 2013 - 04:07 AM
So basically i've written a turtle mining program to my friends. What its supposed to do is:
Branch mine a 1x2 tunnel as long as the player wants (Argument: Length)
Place torches every 8th block
Place a chest in the end of every tunnel with the mined ores/blocks from that run (Argument: chest)
do as many branch mines as the player wants (Argument: Unit)
So I'm not a pro in Lua or ComputerCraft but i do have some experience in programming in generall.
What's the problem?.. You might ask.
I have no idea! The turtle have kinda its own life. It works great until it get to the second tunnel then when it tries to do the home function it stops about 7-8 blocks before it should and the tunnel system gets messy.
Anyway here's the code. In would appreciate any kind of help!
Branch mine a 1x2 tunnel as long as the player wants (Argument: Length)
Place torches every 8th block
Place a chest in the end of every tunnel with the mined ores/blocks from that run (Argument: chest)
do as many branch mines as the player wants (Argument: Unit)
So I'm not a pro in Lua or ComputerCraft but i do have some experience in programming in generall.
What's the problem?.. You might ask.
I have no idea! The turtle have kinda its own life. It works great until it get to the second tunnel then when it tries to do the home function it stops about 7-8 blocks before it should and the tunnel system gets messy.
Anyway here's the code. In would appreciate any kind of help!
local tArgs = { ... }
Length = tonumber(tArgs[1])
unit = tonumber(tArgs[2])
chest = tArgs[3]
if Length == nil then
Length = 5
end
blocksMoved = 0
torchBlocks = 0
function refuel()
turtle.select(1)
if turtle.refuel(0) then
turtle.refuel(1)
end
end
function mine()
if turtle.detect() then
repeat
turtle.dig()
sleep(0.5)
until turtle.detect() == false
end
if turtle.detectUp() then
repeat
turtle.digUp()
sleep(0.5)
until turtle.detectUp() == false
end
turtle.forward()
end
function torch()
turtle.turnRight()
turtle.turnRight()
turtle.select(2)
turtle.place()
turtle.turnLeft()
turtle.turnLeft()
torchBlocks = 0
end
function home()
turtle.digUp()
turtle.up()
for i = 1, blocksMoved do
turtle.back()
sleep(0.1)
end
turtle.down()
blocksMoved = 0
end
function Chest()
turtle.turnRight()
turtle.turnRight()
if turtle.detect() then
repeat
turtle.dig()
sleep(0.5)
until turtle.detect() == false
end
if turtle.detectUp() then
repeat
turtle.digUp()
sleep(0.5)
until turtle.detectUp() == false
end
turtle.forward()
if turtle.detectUp() then
repeat
turtle.digUp()
sleep(0.5)
until turtle.detectUp() == false
end
turtle.back()
turtle.select(3)
turtle.place()
for i = 4, 16 do
turtle.select(i)
turtle.drop()
end
turtle.turnRight()
turtle.turnRight()
end
function repeats()
turtle.turnLeft()
mine()
mine()
mine()
turtle.turnRight()
end
function main()
for i=1, Length do
if turtle.getFuelLevel() < 10 then
refuel()
end
mine()
blocksMoved = blocksMoved + 1
torchBlocks = torchBlocks + 1
print(blocksMoved)
if torchBlocks == 8 then
torch()
end
end
home()
if chest == "y" then
Chest()
end
if unit > 0 then
repeats()
print(blocksMoved)
end
end
while unit >= 0 do
unit = unit -1
main()
end
Edited on 12 December 2013 - 03:08 AM