Posted 07 October 2013 - 03:43 PM
Topic: Redwood lumberjack code help
Hello all!
I am new to programming and quite happy with how far I got, but cannot get my turtle to stop when there is no more tree left.
Program Goal:
1. Have user state how wide a Redwood is.
2. Chop down said tree, refueling along the way and dumping contents into an ender chest
3. Stop when done.
Problem:
Turtle is not stopping when there is no more tree. This started after adding adding code at line 77, i think i have it wrong to tell how many loops to make. Was hoping to have it take 1/2 the number input by the user.
Again, I have never programmed before writing this code, would love to know why the turtle keeps moving and how I can fix it.
Thank you for your help and support!
or http://pastebin.com/pqxfQAEX
Hello all!
I am new to programming and quite happy with how far I got, but cannot get my turtle to stop when there is no more tree left.
Program Goal:
1. Have user state how wide a Redwood is.
2. Chop down said tree, refueling along the way and dumping contents into an ender chest
3. Stop when done.
Problem:
Turtle is not stopping when there is no more tree. This started after adding adding code at line 77, i think i have it wrong to tell how many loops to make. Was hoping to have it take 1/2 the number input by the user.
Again, I have never programmed before writing this code, would love to know why the turtle keeps moving and how I can fix it.
Thank you for your help and support!
Spoiler
function needFuel()
if turtle.getFuelLevel() <= 230 then
turtle.select(2)
turtle.refuel(1)
end
end
function digTop()
while turtle.detect() do
turtle.digUp()
turtle.dig()
turtle.up()
needFuel()
end
while not turtle.detectDown() do
turtle.down()
end
turtle.forward()
end
function nextLeft()
turtle.forward()
turtle.forward()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnLeft()
while not turtle.detect() do
turtle.forward()
end
end
function nextRight()
turtle.forward()
turtle.forward()
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.turnRight()
while not turtle.detect() do
turtle.forward()
end
end
function mailHome()
if turtle.getItemCount(3) ~= 0 then
turtle.dig()
turtle.select(1)
turtle.place()
end
for i = 3,16 do
turtle.select(i)
turtle.drop()
end
turtle.select(1)
turtle.dig()
end
function upBack()
while turtle.detect() do
digTop()
end
mailHome()
nextLeft()
while turtle.detect() do
digTop()
end
mailHome()
nextRight()
end
local tree = ""
print("Lets cut down some trees!")
print("Slot 1 - Ender Chest")
print("Slot 2 - Fuel")
write("Tree width? ")
tree = read()
print("Tree width "..tree)
print("This tree is coming down, you may want to back up...")
for i = 1, tree, 2 do
upBack()
end
or http://pastebin.com/pqxfQAEX