[.14.5] inv has_filters true - get_filter nil

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

[.14.5] inv has_filters true - get_filter nil

Post by Nexela »

In short trying to get the ammo-type from an ammo slot

create a tank and select it
/c inv = game.player.selected.get_inventory(defines.inventory.car_ammo); game.player.print(tostring(inv.has_filters())) -- returns true
/c inv = game.player.selected.get_inventory(defines.inventory.car_ammo); game.player.print(tostring(inv.get_filter(1))) -- returns nil

my assumption is that because it is type and not an item it is returning nil and if this is the case can it be changed to return type if item doesn't exist? or add inventory:get_ammo_filter to return ammo type?
Rseding91
Factorio Staff
Factorio Staff
Posts: 15141
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [.14.5] inv has_filters true - get_filter nil

Post by Rseding91 »

Those 2 functions do 2 completely different things and what you describe is perfectly normal.

An inventory can support filters (thus has_filters() returns true) and have no filters set (thus get_filter(..) returns nil).
If you want to get ahold of me I'm almost always on Discord.
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: [.14.5] inv has_filters true - get_filter nil

Post by Nexela »

Well that explains that.

Any chance for an inventory:get_ammo_category(slot) to return string ammo-type?
User avatar
Mooncat
Smart Inserter
Smart Inserter
Posts: 1207
Joined: Wed May 18, 2016 4:55 pm
Contact:

Re: [.14.5] inv has_filters true - get_filter nil

Post by Mooncat »

Rseding91 wrote:Those 2 functions do 2 completely different things and what you describe is perfectly normal.

An inventory can support filters (thus has_filters() returns true) and have no filters set (thus get_filter(..) returns nil).

hm... maybe a better name for the function? like support_filters()? :P
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: [.14.5] inv has_filters true - get_filter nil

Post by aubergine18 »

or is_filterable()
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
Post Reply

Return to “Modding interface requests”