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

Question About Turtle.getitemcount() - Basic

Started by guamie, 20 August 2013 - 09:34 PM
guamie #1
Posted 20 August 2013 - 11:34 PM
Greetings and Salutations!

I have another question this evening I'm hoping will be easy to answer.

I'm trying to have my turtle look at all 16 slots, add up the total number of items, and then print it. here is how i'm testing this with slot 1 but I'm getting a blank output. I'm sure I'm just doing something wrong with my understanding how to take turtle.getItemCount() output and convert it to a variable.. thanks in advance for how to do this!


flintCount= 0

function flintCounter()
if turtle.getItemCount(1) > 0 then
flintCount = turtle.getItemCount(1)

else
print("Whatchu Talkin Bout Willis?")
end
end

flintCount = flintCounter()
print(flintCount)
Lyqyd #2
Posted 21 August 2013 - 12:21 AM
Moved to Ask a Pro.
jay5476 #3
Posted 21 August 2013 - 01:44 AM
first you try and make flintCount a function it to make this work correctly you would use

return data
where data is your inforamtion you might also want to do this to get all 16 slots

function flint()
  for i = 1, 16 do
  flintCount = flintCount + turtle.getItemCount(i)
  end
return flintCount
end
-- now if you want to get it then do
count = flint()
immibis #4
Posted 21 August 2013 - 07:14 AM
You probably also want to move "flintCount=0" inside the function, so it starts counting from 0 each time.

(In case this reply and the one above it didn't make it clear, your problem is not with turtle.getItemCount, your problem is with functions)