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

Can the Turtle detect specific block types?

Started by petrus4, 04 March 2012 - 12:12 PM
petrus4 #1
Posted 04 March 2012 - 01:12 PM
Hey everyone,
I apologise in advance if this has already been answered somewhere, but if it has, I can't find it. I'm wondering if turtle.detect("blockname") or turtle.detect("blockid") can work to identify specific blocks? I've tried turtle.detect("Trunk") and turtle.detect("trunk"). I thought they worked at first, but they return true if there is anything in front of the Turtle, not just trunk blocks.

Should I be using blockids? Thanks in advance. :unsure:/>/>
Whoaaaaa #2
Posted 04 March 2012 - 01:17 PM
Yes, Here's an example.

while turtle.detect(log) do
turtle.dig()
print ("Found one log")
end
-- If there is a Log in front of the turtle it will destroy it.
while not turtle.detect(log) do
turtle.forward()
end
-- If there isn't a log in front of the turtle, it will keep going forward.
Liraal #3
Posted 04 March 2012 - 01:23 PM
no way, this cannot work. The only way is to mine the thing.
petrus4 #4
Posted 04 March 2012 - 02:00 PM
Unfortunately, it seems that Liraal is right. Thank you for trying to help though, Whoaaaaa.
Espen #5
Posted 04 March 2012 - 02:11 PM
@petrus4:
You could fill the inventory slots of the turtle with one sample of each block type that you want to be able to recognize.
Then after every dig operation you check if the number of one of these slots has increased.
If it has, then you know what has been mined.

But since a turtle only has 9 slots this is limited to some degree.
Since it seems that you want to use this for cutting down trees though, this should not be too much of a problem. :unsure:/>/>
Liraal #6
Posted 04 March 2012 - 02:24 PM
Well Espen, I already implemented a digSlot function in the API. But that's for diamond mining :unsure:/>/>
petrus4 #7
Posted 04 March 2012 - 03:41 PM
Thanks, Espen. I wonder if dan will implement type detection in future? I can hope so. :unsure:/>/>
Espen #8
Posted 04 March 2012 - 04:31 PM
Well Espen, I already implemented a digSlot function in the API. But that's for diamond mining :unsure:/>/>
I hope I'm not derailing this topic too much by asking this, but I took a look at your digSlot() function and I have to say I'm a bit confused.
If you e.g. use digSlot(5) but the turtle digs a block that increases another Slot, e.g. Slot 3, then digSlot() will drop what's in Slot 3 and return true.
Whereas if it would've dug a block that actually increased Slot 5, then it would return false?

So is digSlot(slotnumber) supposed to return true if the turtle didn't mine a block in 'slotnumber', but return false if it did? *headscratch*
If that is what's actually happening and if this also is the intended behavior, then could you perhaps explain what exactly the digSlot() is supposed to do?
I hope you don't mind, it's just that I'm confused and curious at the same time.^^
Liraal #9
Posted 04 March 2012 - 04:41 PM
Well, all that except for the true/false, I must've messed them up :unsure:/>/>

The intended behavior is that when mining for diamond, it'll drop everything else (such as cobble). I don't have that perfected yet though, but it works pretty well.
Espen #10
Posted 04 March 2012 - 04:45 PM
Ah, ok that explains it then. Thx.
CCJJSax #11
Posted 19 March 2013 - 05:37 PM
I know I'm a bit late to the party here, but there is one tedious way, and it only works on things that have a placeable block, like cobble. if you have a piece of cobble in the turtle's currently selected slot, you could do turtle.compare() and as long as there is a cobble block in front of the turtle it will come back true. I really wish there was an easier way, but if there is, I haven't found it.

I did just find a separate mod that works with computercraft, called item analyzer mod (if memory serves) and it can do that, if you want that.
Cruor #12
Posted 19 March 2013 - 08:40 PM
Locked to keep the foul magic from spreading D: