Jump to content




How to get total items in a turtle?

turtle

  • You cannot reply to this topic
1 reply to this topic

#1 pb2007

  • Members
  • 6 posts

Posted 16 April 2017 - 01: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?

#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 16 April 2017 - 01: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)






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users