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

How i can compare one slot to other?

Started by PedroBarbosa, 20 December 2012 - 04:11 PM
PedroBarbosa #1
Posted 20 December 2012 - 05:11 PM
Hi guys, i need something like this:
I got obsidian in slot nº16 and i need to see if obsidian is in other slots…
Somebody can help?

Merry Christmas
Orwell #2
Posted 20 December 2012 - 05:19 PM

local function getSlots(slotNum)
  local slots = {}
  turtle.select(slotNum)
  for i=1,16 do
	if i~=slotNum and turtle.compareTo(i) then
	  table.insert(slots, i)
	end
  end
  return slots
end
print("Slots containing the same item as slot 16:")

textutils.tabulate(  getSlots(16) )
PedroBarbosa #3
Posted 20 December 2012 - 05:36 PM
Can you explain what is textutils.tabulate?
Orwell #4
Posted 20 December 2012 - 05:38 PM
It prints a table of strings/numbers in a tabulated manner (like, the one next to the other, with spacing).