Posted 26 February 2012 - 03:05 PM
I saw this mod on reddit and found it interesting. To learn a bit coding I decided to imrpove "lumberjack turtle" code from the video. Here is what I have:
I want turtle to chop down the tree then walk randomly (couldn't think of better system for finding trees), and chop down tree when he meets one
My problem is when turtle meet an obstacle, it freezes. I'm guessing I used "return" wrong in function drzewo(), but I don't know how to use it correctly. I am only starting out with programming and make many mistakes, so probably it's stupid mistake.
function drzewo()
repeat
if turtle.detect()==true then
turtle.dig()
turtle.up()
elseif turtle.detectUp()==true then
turtle.digUp()
turtle.up()
elseif turtle.detectUp()==false and turtle.detect()==false and turtle.detectDown()==false then
turtle.down()
end
until turtle.detect()==false and turtle.detectDown()==true and turtle.detectUp==false
do return end
end
while 1==1 do
while turtle.detect()==false do
x=math.random(6)
if x==1 or x==2 or x==3 then
turtle.forward()
elseif x==4 then
turtle.turnLeft()
elseif x==5 then
turtle.turnRight()
elseif x==6 then
turtle.turnRight()
turtle.turnRight()
end
end
while turtle.detect()==true do
drzewo()
end
end
I want turtle to chop down the tree then walk randomly (couldn't think of better system for finding trees), and chop down tree when he meets one
My problem is when turtle meet an obstacle, it freezes. I'm guessing I used "return" wrong in function drzewo(), but I don't know how to use it correctly. I am only starting out with programming and make many mistakes, so probably it's stupid mistake.