Posted 14 July 2016 - 05:13 AM
I'm trying to sort of follow a tutorial but also not just straight up copy it for making a tree farming turtle. Knowing very little about Lua, but having pretty extensive programming knowledge (from Javascript to PHP to C#, etc.) I can't figure any reason this shouldn't work, it's kinda irritating. In my test setup I have rubber saplings in slot 1 and bonemeal in slot 2. I should also specify I'm playing on ComputerCraft 1.63. For reasons out of my control I have to play on an old modpack. Anywho, my code:
Pretty straightforward. If there's more than one sapling in the first slot, place it, then, while the block in front of the turtle is the same as the selected slot (slot 1, so saplings), switch to slot 2 and use a bonemeal, then switch back to slot 1 for another compare. Once the block in front is no longer a sapling, dig, move into that spot, dig up until there's nothing left, then move back down and back into the starting position.
The issue I'm having is that it either doesn't seem to detect that the block in front of it is a sapling, or it will only detect it once. I wrote this test program to see if I could make sense of what was going on:
I figured I'd just keep running test and I'd get the "sapling" output and a bonemeal use until the tree was grown, but no. I manually place a sapling in front of the turtle, run test the first time it outputs "sapling" and uses a bonemeal. The tree hasn't grown, but when I run it again, it says "not sapling" and breaks the sapling.
I'm confused and at a loss. The only thing I can think is that "place"-ing bonemeal changes something in front of the turtle making it no longer detect that it's a sapling. Any help would be very appreciated!
while turtle.getItemCount(1) > 1 do
turtle.select(1)
turtle.place()
while turtle.compare() do
turtle.select(2)
turtle.place()
turtle.select(1)
end
turtle.dig()
turtle.forward()
while turtle.detectUp() do
turtle.digUp()
turtle.up()
end
while turtle.detectDown() == false do
turtle.down()
end
turtle.back()
end
Pretty straightforward. If there's more than one sapling in the first slot, place it, then, while the block in front of the turtle is the same as the selected slot (slot 1, so saplings), switch to slot 2 and use a bonemeal, then switch back to slot 1 for another compare. Once the block in front is no longer a sapling, dig, move into that spot, dig up until there's nothing left, then move back down and back into the starting position.
The issue I'm having is that it either doesn't seem to detect that the block in front of it is a sapling, or it will only detect it once. I wrote this test program to see if I could make sense of what was going on:
if turtle.compare() then
print("sapling")
turtle.select(2)
turtle.place()
turtle.select(1)
else
print("not sapling")
turtle.dig()
end
I figured I'd just keep running test and I'd get the "sapling" output and a bonemeal use until the tree was grown, but no. I manually place a sapling in front of the turtle, run test the first time it outputs "sapling" and uses a bonemeal. The tree hasn't grown, but when I run it again, it says "not sapling" and breaks the sapling.
I'm confused and at a loss. The only thing I can think is that "place"-ing bonemeal changes something in front of the turtle making it no longer detect that it's a sapling. Any help would be very appreciated!