This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Buho's profile picture

turtle.compare() fails on partially-fertilized saplings

Started by Buho, 02 May 2013 - 01:23 PM
Buho #1
Posted 02 May 2013 - 03:23 PM
It took me a couple of hours to track this bug down in my code. This is for a tree farmer. The first two lines of this code were failing:

turtle.select(2)
if turtle.compare() then
    fertilize()
    chop()
    replant()
else
    moveThruTree()
end
moveToNextTree()

Slot 2 has a sample sapling. What it's supposed to do is detect if the block is a sapling. If so, fertilize it, then harvest the tree. Normally this works fine, but I found that once out of four times or so it plows right through the sapling without attempting to fertilize it. I checked this part of my code over and over and all was fine.

But I just now thought to partially-fertilize the sapling and then compare. Sure enough, it fails. A partially-fertilized sapling block does not match the sapling item. I imagine a partially-grown tree fails, too (which is normally the case for my failures).

I will rewrite this chunk of code to test the negative case instead (compare a block of wood, slot 1), but I wondered if there's another way to compare saplings or if this is a bug or whatever.
theoriginalbit #2
Posted 02 May 2013 - 03:29 PM
Saplings metadata changes over time, and this is why it sometimes ploughs right through it. The easiest thing to do is use a wood block instead. then if it doesn't match move on, its and then chop down the tree.