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

Code for dropping certain items out of a turtle misidentifying all items as the ones in the first slot

Started by 9315808, 12 September 2015 - 04:07 PM
9315808 #1
Posted 12 September 2015 - 06:07 PM
This function, whenever run, will always drop the item in the first slot correctly, but will misidentify all the other items in the turtle's inventory as the same item, so if it's, say, an ore, it will be dropped as if it was cobblestone, sand, etc.


function junk()
  for i = 1, 16 do
	turtle.select(i)
	if items[data.name] then
	  turtle.drop()
	  print(data.name)
	else
	  print("No unwanted items")
	end
  end
  turtle.select(1)  
end

The variable items is this


local items = {
  ["minecraft:cobblestone"] = true,
  ["minecraft:dirt"] = true,
  ["minecraft:gravel"] = true,
  ["minecraft:sand"] = true,
  ["minecraft:sandstone"] = true,
  ["chisel:granite"] = true,
  ["chisel:diorite"] = true,
  ["chisel:andesite"] = true,
  ["chisel:marble"] = true,
}

And the variable data is


local data = turtle.getItemDetail()

Here's the full program: http://pastebin.com/9BQagRKS
Edited on 12 September 2015 - 11:20 PM
Lyqyd #2
Posted 12 September 2015 - 11:42 PM
You don't appear to be actually looking up the data again for each slot. It looks like you get the information once and then never update it. You really need to post the whole code, though. Then we can be sure.
9315808 #3
Posted 13 September 2015 - 12:22 AM
Here it is: http://pastebin.com/9BQagRKS
Lyqyd #4
Posted 13 September 2015 - 04:32 AM
So yes, the problem is that you only call turtle.getItemDetail() once, so the data table will never change after that.