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

Help -- Getting quantity of an item in a slot of a chest.

Started by _Astro_, 17 September 2016 - 06:24 PM
_Astro_ #1
Posted 17 September 2016 - 08:24 PM
Hello,
If anyone could help been having trouble (I think) with peripherals++ . I have a chest next to a computer set as a peripheral, I getStackInSlot(1) of said chest and then I print the name and the quanity, only problem is I can't print the quanitity and don't know and can't find out how. Would be really appreciated if someone could please help. :D/>
Lyqyd #2
Posted 18 September 2016 - 01:02 AM
Moved to Ask a Pro.

That's probably OpenPeripheral rather than Peripherals++.
KingofGamesYami #3
Posted 18 September 2016 - 01:58 AM

print( textutils.serialize( c.getStackInSlot(1) ) )

Assuming c is the wrapped chest, what does this output?
Edited on 17 September 2016 - 11:59 PM
Sewbacca #4
Posted 18 September 2016 - 08:30 AM
If KingofGamesYami solution errors (it shouldn't), then try:

local serializeSafe
serializeSafe = function (tab) 
  for key, value un pairs(tab) do
    print(key, '=', tostring(value))
    if type(value) == 'table' then
      serializeSafe(value) 
    end
  end
end

Sure, this solution isn't fine, but I am online on my mobile.
Lupus590 #5
Posted 19 September 2016 - 01:50 PM
If KingofGamesYami solution errors (it shouldn't), then try:

local serializeSafe
serializeSafe = function
 (tab)
  for key, value in pairs(tab) do
	print(key, '=', tostring(value))
	if type(value) == 'table' then
	  serializeSafe(value)
	end
  end
end
fixed it for you
Edited on 19 September 2016 - 12:38 PM
Sewbacca #6
Posted 19 September 2016 - 02:34 PM
If KingofGamesYami solution errors (it shouldn't), then try:

local function serializeSafe (tab)
  for key, value in pairs(tab) do
	print(key, '=', tostring(value))
	if type(value) == 'table' then
	  serializeSafe(value)
	end
  end
end
fixed it for you

You edited just
local serializeSafe;
serializeSafe = function …
to
local serializeSafe = function …
what will errors, because the function can only call itself (just in case, the function is local) if the variable is predeclared.

I meant the output wouldn't be fine.
Lupus590 #7
Posted 19 September 2016 - 02:39 PM
reverted to just fix in for loop
Sewbacca #8
Posted 21 September 2016 - 10:39 PM
reverted to just fix in for loop
I didn't got what you mean.
KingofGamesYami #9
Posted 21 September 2016 - 10:57 PM
The correct spelling of 'in' is in, not un. You should test your code before posting.
Sewbacca #10
Posted 22 September 2016 - 12:38 PM
The correct spelling of 'in' is in, not un. You should test your code before posting.
Oh i see, but i was online on my mobile.