Posted 20 July 2013 - 09:03 PM
title:advansed tree farm using turtle with occasional error
Ok, I like to think I'm a fairly good programer, but this lua stuff is different enough from VB or C# to cause me extreme frustration. I just wrote a tree farm program that <should> detect the with of the tree and the side of a 2 wide tree it was placed on and cut it down every 5 minutes, remove sapling drops from a chest below put everything in a "return chest" above it and keep charcoal stocked from it's left. but about every 3 tree cycles very consistently it only cuts down 1/2 the 2 wide tree. I'm frustrated with the whole thing and am fed up with debugging if someone could help I would be very greatfull. pleas excuse my spelling, it's not my speciality and I would appreciate the pointing out of any bad practises in my code, I'v never before programed computercraft of lua. here is all you should need to know:
the code:
pics of the error:
the turtle should have been one block forward and the whole tree should have been cut and replanted, the previous 2 times, you can see in the last pic, went fine.
please help a fellow programer, sencerly
tebbenjo
Ok, I like to think I'm a fairly good programer, but this lua stuff is different enough from VB or C# to cause me extreme frustration. I just wrote a tree farm program that <should> detect the with of the tree and the side of a 2 wide tree it was placed on and cut it down every 5 minutes, remove sapling drops from a chest below put everything in a "return chest" above it and keep charcoal stocked from it's left. but about every 3 tree cycles very consistently it only cuts down 1/2 the 2 wide tree. I'm frustrated with the whole thing and am fed up with debugging if someone could help I would be very greatfull. pleas excuse my spelling, it's not my speciality and I would appreciate the pointing out of any bad practises in my code, I'v never before programed computercraft of lua. here is all you should need to know:
the code:
--/lua
--tebbenjo
replant = true
hight = 0
function fuel()
if turtle.getFuelLevel() < 1 then
turtle.select(2)
if turtle.refuel(1) then
print "refueled"
else
for n=1,16 do
if turtle.getItemCount(n) > 0 then
if turtle.refuel(n) then
break
end
end
end
end
turtle.select(1)
end
end
function down()
for h=0,hight do
fuel()
turtle.down()
end
end
function up()
while not turtle.up() do
fuel()
turtle.digUp()
turtle.up()
hight = hight + 1
end
end
function digDown()
for h=0,hight do
fuel()
turtle.digDown()
turtle.down()
end
end
function side()
up()
turtle.dig()
turtle.forward()
digDown()
end
while true do
os.startTimer(300)
local event = os.pullEvent("timer")
for d=1,8 do
fuel()
turtle.forward()
end
if turtle.detect() then
fuel()
turtle.down()
fuel()
turtle.dig()
fuel()
turtle.forward()
if turtle.detect() then
hight = 0
print "2x2 gerth detected"
side()
hight = 0
fuel()
turtle.turnRight()
if turtle.detect() then
print "I started on the Left side"
fuel()
turtle.dig()
fuel()
turtle.forward()
fuel()
turtle.turnRight()
side()
if replant then
fuel()
turtle.turnRight()
fuel()
turtle.turnRight()
turtle.place()
fuel()
turtle.turnLeft()
fuel()
turtle.forward()
fuel()
turtle.turnRight()
turtle.place()
fuel()
turtle.turnRight()
turtle.place()
fuel()
turtle.turnLeft()
fuel()
turtle.back()
turtle.place()
else
fuel()
turtle.turnRight()
fuel()
turtle.forward()
fuel()
turtle.turnRight()
fuel()
turtle.back()
end
else
print "I started on the Right side"
fuel()
turtle.turnLeft()
fuel()
turtle.turnLeft()
turtle.dig()
fuel()
turtle.forward()
fuel()
turtle.turnLeft()
side()
if replant then
fuel()
turtle.turnLeft()
fuel()
turtle.turnLeft()
turtle.place()
fuel()
turtle.turnRight()
fuel()
turtle.forward()
fuel()
turtle.turnLeft()
turtle.place()
fuel()
turtle.turnLeft()
turtle.place()
fuel()
turtle.turnRight()
fuel()
turtle.back()
turtle.place()
else
fuel()
turtle.turnLeft()
fuel()
turtle.forward()
fuel()
turtle.turnLeft()
fuel()
turtle.back()
end
end
else
hight = 0
print "1x1 gerth detected"
up()
down()
fuel()
turtle.back()
if replant then
turtle.place()
end
end
fuel()
turtle.up()
for d=1,8 do
fuel()
turtle.back()
end
while turtle.suckDown() do
end
for s=3,16 do
if turtle.getItemCount(s) > 0 then
turtle.select(s)
turtle.dropUp(turtle.getItemCount(s))
end
end
turtle.select(1)
else
print ("tree not grown at: " .. textutils.formatTime(os.time(), true))
for d=1,8 do
fuel()
turtle.back()
end
end
if turtle.getItemCount(2) < 64 then
turtle.select(2)
fuel()
turtle.turnLeft()
turtle.suck()
turtle.select(3)
turtle.drop(turtle.getItemCount(3))
turtle.select(1)
fuel()
turtle.turnRight()
end
end
--/eof
pics of the error:
the turtle should have been one block forward and the whole tree should have been cut and replanted, the previous 2 times, you can see in the last pic, went fine.
please help a fellow programer, sencerly
tebbenjo