I was going to write a simple "me too:" I'm also a bit annoyed that there isn't (as far as I can tell) a function for getting the number of slots on a robot's own inventory.
The documentation says that the own inventory is accessed with sides.back but that returns an "invalid side" error.
My guess is that the "historic" ability to use getStackInSlot() for the robot's internal API went from "deprecated" to "scrapped" but the author forgot to provide a replacement for getInventorySize() .
Anyway, happily for both of us, there's a workaround: The function getStackInInternalSlot() errors out if you call it with an out-of-range slot number. So what I did was to count up slots and caught the error:
local s, lastSlot = 1, 0;
while true do
local stat, stk = pcall(invcon.getStackInInternalSlot, s)
if stat then lastSlot = s; s = s + 1 else break end
end
print(string.format("Last slot: %d", lastSlot))
This gave me the correct inventory size for my cheap single inventory upgrade robot with 16 slots.
Realistically, it's probably enough (and more efficient) to just test sizes of 16, 32, 48 and 64, because it seems inventory upgrades are 16 slots each and you can only install up to 4 of them.
robot and inventory controller upgrade
in Miscellaneous
Posted
I was going to write a simple "me too:" I'm also a bit annoyed that there isn't (as far as I can tell) a function for getting the number of slots on a robot's own inventory.
The documentation says that the own inventory is accessed with sides.back but that returns an "invalid side" error.
My guess is that the "historic" ability to use getStackInSlot() for the robot's internal API went from "deprecated" to "scrapped" but the author forgot to provide a replacement for getInventorySize() .
Anyway, happily for both of us, there's a workaround: The function getStackInInternalSlot() errors out if you call it with an out-of-range slot number. So what I did was to count up slots and caught the error:
local s, lastSlot = 1, 0; while true do local stat, stk = pcall(invcon.getStackInInternalSlot, s) if stat then lastSlot = s; s = s + 1 else break end end print(string.format("Last slot: %d", lastSlot))
This gave me the correct inventory size for my cheap single inventory upgrade robot with 16 slots.
Realistically, it's probably enough (and more efficient) to just test sizes of 16, 32, 48 and 64, because it seems inventory upgrades are 16 slots each and you can only install up to 4 of them.