Well there is no way at the moment. Sadly tools are not peripherals for the turtles, so we have no way of detecting… However any peripherals added to turtles by MiscPeripherals or the such there is a solution:
Note: This solution does not work for all turtles! Only peripheral turtles, it cannot detect tools (i.e. wrenches, tree taps, shears, etc)Using the peripheral API we can use the function `getType` to determine the type of peripheral… for example the following code checks to see if the turtle has a crafting table
if not (peripheral.getType("left") == "workbench" or peripheral.getType("right") == "workbench") then
error("Turtle is not a crafty turtle!", 0)
end
obviously the easier solution for the above is
if not turtle.craft then
error("Turtle is not a crafty turtle", 0)
end
Obviously the logic from the first one can be continued for any peripheral…. example: MiscPeripheral's Inventory Turtle will contain a peripheral on the left or right with the type "inventory".
The second logic can be followed for very few turtles as to check existence of a function you must first wrap the peripheral, meaning you know it's there… of course you could do something like this (assuming a chatbox turtle):
local left = peripheral.wrap("left") or {} --# creating the table is important to not have it error on line 3
local right = peripheral.wrap("right") or {}
if not (left.say or right.say) then
error("No chatbox attached", 0)
end
but again, the above method would just be easier to use the first way of just checking the peripheral's existence.
And of course sadly the problem with attempting to check the tools, lots of them use turtle.attack() to interact and some use turtle.dig() too. So since they have no unique function there is no sure way to check and know what they are.