Page 1 of 1

LuaInventory return number of filtered slots

Posted: Tue Apr 04, 2017 12:37 pm
by Optera
Please add a way to quickly check the amount of filtered/blocked slots in an inventory.
Going through every single slot is very time consuming for many or very large inventories when all you need is the amount of free slots.

Example:
I want to support players using filters in Logistic Train Network. I'd have to check every slot in every wagon in every train when deciding if a train has enough cargo space.

Re: LuaInventory return number of filtered slots

Posted: Tue Apr 04, 2017 1:56 pm
by Rseding91
Optera wrote:Please add a way to quickly check the amount of filtered/blocked slots in an inventory.
Going through every single slot is very time consuming for many or very large inventories when all you need is the amount of free slots.
That's what the game does already every time anything interacts with a filtered inventory and one of the reasons why logistics containers don't support filters.

Re: LuaInventory return number of filtered slots

Posted: Tue Apr 04, 2017 2:49 pm
by Optera
Rseding91 wrote: That's what the game does already every time anything interacts with a filtered inventory and one of the reasons why logistics containers don't support filters.
If you do it internally already please make it also available through the api.

Re: LuaInventory return number of filtered slots

Posted: Tue Apr 04, 2017 5:00 pm
by Rseding91
Optera wrote:
Rseding91 wrote: That's what the game does already every time anything interacts with a filtered inventory and one of the reasons why logistics containers don't support filters.
If you do it internally already please make it also available through the api.
It is: can_insert already checks filtered slots.

Re: LuaInventory return number of filtered slots

Posted: Tue Apr 04, 2017 5:45 pm
by Optera
Rseding91 wrote:
Optera wrote:
Rseding91 wrote: That's what the game does already every time anything interacts with a filtered inventory and one of the reasons why logistics containers don't support filters.
If you do it internally already please make it also available through the api.
It is: can_insert already checks filtered slots.
can_insert returns bool if some items can be inserted, which is useless if i need to know exactly how much free space there is.
get_filter requires to iterate over every signle slot and check if it's nil.

If it doesn't exist internally already adding parameters to Inventory objects storing filtered, blocked and free slot indexes would simplify and increase access to specific slots removing the need to iterate over whole inventories when changing filters, which is time consuming in C and even more in lua.
This information should be passed through the api as well.