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

turtle.getItemName(number slotNum)

Started by databrain, 14 August 2014 - 07:47 PM
databrain #1
Posted 14 August 2014 - 09:47 PM
My suggestion seems to have been semi-suggested before, and turned down, however, at least with what I could find with the search feature, none of them state what I have in mind for this implementation.

Most of my experience with ComputerCraft has to do with turtles. I use a turtle for about everything, and nothing I make is very user-friendly. Most people who want to use my programs don't understand how to use my turtle the exact way it should be used, all for the reason of tedium on setting up a turtle for a specific program.

I use a setup similar to what Ben made in his ComputerCraft Challange series for my mining turtle. It's great and all, and it's useful for only getting the valuable resources. However, none of this is user friendly. It's a becoming more and more of annoyance to have to tell anyone using the program to place an arbitrary item in an arbitrary slot number.

I personally like to make fully automated robots, and this really becomes a big issue when you are working on massive modpacks with annoying pointless ores *cough* GeoStrata *cough*. I'm not asking for the ability to detect the ID of blocks surrounding the turtle, I am simply asking for the ability to detect the name of an item currently in the inventory of a turtle.

This would be a big help in making user-friendly robots, as I would only need the turtle to ask for fuel, start digging straight down, and putting blocks mined in their respective arbitrary slots.

Most previously suggested features, mainly about detecting nearby blocks and their IDs, were turned down, because of the already-existing block detection features, which are limited, but at least usable. However, they are not in the least User-friendly when it comes to developing programs for those who don't know how to make their own.

It is quite annoying to have to tell people "You have to put dirt in slot 1, stone in slot 2, gravel in slot 3, and fuel in slot 16!".

And of course, the most annoying of all, which adding some sort of implementation will definitely fix, is that robots cannot be fully autonomous. When I have my fuel slot at 16, any coal mined will be added into a different stack, rather than the 16'th stack. If there was any possible way to detect what fuel is, autonomous turtles could easily maintain fuel. I had to switch to coal blocks, and get a stack of that, so that my turtle wouldn't run out soon. However, a stack of coal blocks worth of fuel is not indefinite. If we could have simple implementations to detect the name of an item, we could finally make turtles that can sustain their own fuel source.

So that is my suggestion for one simple function that can and will definitely encourage players to make turtle programs and help fuel the turtle developing community,
turtle.getItemName(number slotNum), which will return a string, the name of the item. (Possibly the ID?)
Lyqyd #2
Posted 14 August 2014 - 09:53 PM
That's not likely to happen, as direct knowledge of what a slot contains has been rejected many, many times. You can compare internally with turtle.compareTo, if you want to verify that two slots contain the same thing, or use turtle.refuel to determine if something is a fuel (though I believe you have to attempt to consume at least one item in the stack to determine that).
Cranium #3
Posted 14 August 2014 - 11:41 PM
This is already available through OpenPeripheral and their narcissistic turtles.
wieselkatze #4
Posted 15 August 2014 - 12:17 PM
You can actually check if the item in one slot is a valid fuel. To transfer it just use the following function.


for i = 4, 15 do
  if turtle.getItemCount(i) > 0 then
    turtle.select(i)
    if turtle.refuel(0) then
	  turtle.transferTo(16)
    end
  end
end

Would actually be kinda useful for 'vanilla' ComputerCraft without OpenPeripherals though.
Edited on 15 August 2014 - 10:18 AM
immibis #5
Posted 25 August 2014 - 04:16 AM
When your mining turtle returns to base, have it pass each stack to another turtle that has 16 different items. The second turtle can then detect what it stacked with, and from that know the type of the item.

Of course it still requires manual setup, but after that it's automatic.