Trying to pull lists of items from chest

Started by DrStein, Jul 05, 2020, 07:05 AM

Previous topic - Next topic

DrStein

I'm trying to get a list of items that are in the chest using .GetItemMeta(). Specifically I'm trying to print the Slot, Display Name and Itemcount to the right monitor. I get an error when attempting to run the code

test.lua:7: attempt to concatenate field 'count' (a nil value)
Below is the full code I'm trying to run

monitor = peripheral.wrap("right")
chest = peripheral.wrap("left")
y = 1

for slot, item in pairs(chest.getItemMeta(y)) do
  monitor.setCursorPos(1, y)
  monitor.write(y .. " " .. item.displayName .. " " .. item.count)
  y = y + 1
end

Any help would be greatly appreciated :)

pjals

Quote from: DrStein on Jul 05, 2020, 07:05 AMmonitor.write(y .. " " .. item.displayName .. " " .. item.count)
replace
monitor.write(y .. " " .. item.displayName .. " " .. item.count) with
monitor.write(y .. " " .. item.displayName .. " " .. item.count or 1)
hi i am T79, bye

SquidDev

#2
Quote from: pjals on Jul 05, 2020, 11:22 AM-snip-
That won't work - you'd need to do (item.count or 1). However, this whole thing is a bit strange - count should never be missing. It might be worth doing print(textutils.serialize(item)), and seeing what properties it has.
GitHub | CC:Tweaked: A ComputerCraft fork | Plethora: A peripheral mod