Jump to content




turtle.compare() fails on partially-fertilized saplings


  • You cannot reply to this topic
1 reply to this topic

#1 Buho

  • Members
  • 110 posts

Posted 02 May 2013 - 02: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.

#2 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 02 May 2013 - 02: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.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users