Jump to content

Recommended Posts

The Inventory:GetNextAvailableSlot method is very helpful for finding empty inventory slots for items to go in (it handles stacks, too, which is very, very useful). Unfortunately, the backpack object seems to be an Container component instead of an Inventory component, and so doesn't have this method or an equivalent.

 

Not knowing if there's a formal feedback system for suggesting mod API improvements: Klei, please add an equivalent of Inventory:GetNextAvailableSlot to the Container component.

 

There's some precedence for this, because a GiveItem method exists in both components.

 

The use case is finding the best (possibly empty) slot for an item to be placed in, in the player's backpack or in chests.

@DJPaul,

 

While the inventory component itself isn't a container, its item slots are a container, and the equip slots are a different container.

GetNextAvailableSlot actually also checks the overflow container for available slots.  (Backpacks are considered your inventory's overflow container, when they're equipped).

 

GetNextAvailableSlot returns two values, the first is the slot, and the second is the container that it found free space in.  The container can be itemslots, equipslots, or overflow.

Thanks; I think my suggestion has some merit for it, which is why I started a topic. My proposed use case is finding the best slot in a chest or backpack (etc), not just the best slot within a player's overall inventory space (which may be within the backpack, as you said). It's easy, certainly, to create your own function that does this (I have), but it feels like a hole in the mod API. :)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...