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

How to get total items in a turtle?

Started by pb2007, 16 April 2017 - 12:36 PM
pb2007 #1
Posted 16 April 2017 - 02:36 PM
I'm trying to make a cobblestone generator for my turtle (it's advanced if that matters) and write the total items in its inventory to a monitor below quickly. I set the monitor to the variable "m" using peripheral.wrap(). Do I have to do

local a = turtle.getItemCount(1)
local b = turtle.getItemCount(2)
-- and so on and so forth
and then do

local total = a + b + c + d -- and so on
m.write(total .. "items are in the turtle.")
or can I put it in a table, or maybe use:

turtle.getItemCount(0)
I really don't know how I can do this. So can you help me?
Bomb Bloke #2
Posted 16 April 2017 - 02:50 PM
This is where you want to make use of a for loop:

local count = 0

for i = 1, 16 do
  count = count + turtle.getItemCount(i)
end

print(count)