3 posts
Posted 29 July 2013 - 01:28 PM
Help with simple woodcutter
I want my mining turtle to cut down a tree, I wrote this but it won't move or say anything.
function cut()
turtle.detectUp() then
turtle.digUp()
turtle.up()
cut()
end
end
1190 posts
Location
RHIT
Posted 30 July 2013 - 01:57 AM
You never call the function from outside. Regardless, the behavior of your function would not be what you expect. It would just continue to dig up until it hit the block limit and/or the loop limit. Here's a better system:
for i=1,16 do --#First off, select a slot that has nothing in it so that we can compare the logs as we dig upwards
if turtle.getItemCount(i) == 0 then
turtle.select(i) --#Accidentally forgot the i
break
end
end
local function tree()
turtle.dig()
turtle.forward() --#Position ourselves under the tree
while turtle.compareUp() do --#This compares the log that we dug getting positioned to the log directly above the turtle.
--#This loop will end as soon as the block above the turtle no longer matches the log in its inventory
turtle.digUp()
turtle.up()
end
while turtle.down() do end --#While the turtle can go down it will continue to do so
end
tree() --#Don't forget to actually call the function
3 posts
Posted 30 July 2013 - 07:20 PM
I tried that and it says turtle:18: Expected Number
1190 posts
Location
RHIT
Posted 30 July 2013 - 08:18 PM
I tried that and it says turtle:18: Expected Number
Oops. I updated my OP. Just forgot to put the i variable into turtle.select on line 3.
7 posts
Posted 30 July 2013 - 08:24 PM
I tried that and it says turtle:18: Expected Number
Oops. I updated my OP. Just forgot to put the i variable into turtle.select on line 3.
And that explains why I couldn't find the bug, you were too fast for me bubba
331 posts
Posted 01 August 2013 - 06:11 AM
you are using
turtle.detectUp() then
when you should be using
if turtle.detectUp() then
also calling your function within your function will cause a stack error.