Jump to content




Item Detector Code?

turtle

  • You cannot reply to this topic
5 replies to this topic

#1 moneymaster2012

  • Members
  • 38 posts

Posted 07 June 2015 - 02:03 AM

What's going on, guys?

I've heard that there is code where a turtle can sense how many and what type of items it picks up. I am basically making a bank-type program. I want a certain amount of one item to execute a command (such as redstone.setOutput()). Help will be much appreciated. Thanks!

#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 07 June 2015 - 02:09 AM

turtle.getItemDetail

#3 moneymaster2012

  • Members
  • 38 posts

Posted 07 June 2015 - 02:35 PM

View PostKingofGamesYami, on 07 June 2015 - 02:09 AM, said:

Thanks, but I want to make an "if" statement with this info. Something like: 'if data == "iron_ingot" then'.

#4 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 07 June 2015 - 02:50 PM

So do that.

local data = turtle.getItemDetail()

if data and data.name == "minecraft:iron_ingot" then  -- If data is defined (meaning there was an item in the slot), and the item's name matches, then...
  -- whatever
end

It is, of course, rather difficult to tell you how to improve your script if you don't want to show it to us.

#5 moneymaster2012

  • Members
  • 38 posts

Posted 07 June 2015 - 03:23 PM

View PostBomb Bloke, on 07 June 2015 - 02:50 PM, said:

So do that.

local data = turtle.getItemDetail()

if data and data.name == "minecraft:iron_ingot" then  -- If data is defined (meaning there was an item in the slot), and the item's name matches, then...
  -- whatever
end

It is, of course, rather difficult to tell you how to improve your script if you don't want to show it to us.
Still doesn't work... I am on minecraft 1.7.10, does it work there?

#6 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 07 June 2015 - 04:31 PM

MC version rarely makes a difference in CC features, the CC version is more important. However, if you had said minecraft 1.6, I could've told you it isn't added yet.

if the script BB provided errors with
filename:1:attempt to call nil

...You don't have that functionality in your version of CC, and may want to consider updating.

If you used his code and nothing happened, you do have the functionality but didn't add any code inside the if statement provided, or the turtle didn't find an iron ingot in the currently selected slot (default is slot 1, upper left).






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users