Filters for selection-tool not working as expected

Bugs that are actually features.
Post Reply
Pi-C
Smart Inserter
Smart Inserter
Posts: 1700
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Filters for selection-tool not working as expected

Post by Pi-C »

I've created this selection-tool:

Code: Select all

local tool =  {
  type                                  = "selection-tool",
  name                                  = GCKI.carkey_name,

  entity_filter_mode			= "whitelist",
  entity_type_filters                   = {"car", "spider-vehicle"},
  selection_mode                        = {"entity-with-owner", "avoid-rolling-stock"},
  selection_color                       = {g = 1},
  selection_cursor_box_type             = "entity",
}
data:extend({tool})
In data-final-fixes.lua, I sort out the names of prototypes I want to ignore and add the renaming names to entity_filters:

Code: Select all


local keys = data.raw["selection-tool"][GCKI.carkey_name]
keys.entity_filters = { "name_1", "name_2", "name_3" }
The prototype browser shows that the filters have been applied. However, when I select an area with the tool, the selection includes entities that are based on prototypes not mentioned in keys.entity_filters.

I got the expected result when I removed entity_type_filters. I therefore suspect that tool.entity_filters and tool.entity_type_filters are ORed instead of ANDed (the same applies for alt_entity_filters and alt_entity_type_filters). In my opinion, this behavior is unexpected because it makes the filters more general where they should be more precise.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Rseding91
Factorio Staff
Factorio Staff
Posts: 13345
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Filters for selection-tool not working as expected

Post by Rseding91 »

Thanks for the report however that's working as intended. If you don't want the filters "ORd" then just delete the entity type filters and use the entity filters.
If you want to get ahold of me I'm almost always on Discord.

Pi-C
Smart Inserter
Smart Inserter
Posts: 1700
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Filters for selection-tool not working as expected

Post by Pi-C »

Rseding91 wrote:
Thu Jul 07, 2022 5:16 pm
Thanks for the report however that's working as intended. If you don't want the filters "ORd" then just delete the entity type filters and use the entity filters.
Thanks for the answer. I realize that things are a bit more complex than I've assumed when writing my report. Deleting the type filters will work in the case I presented (when filters are used in "whitelist" mode) because the list of name filters should include only names of prototypes with the correct type. But that can't work in "blacklist" mode, as it would literally find everything that doesn't match the name pattern.

Why suddenly turning to blacklists? I assume that filtering works like this: You select an area with the selection tool. For each entity found inside the area, you loop over the name list and check if the entity's name matches any name from the list. So it would be of advantage to keep that list as short as possible (speed gain as the maximum number of loop iterations is lower, and increased readability of code and logs). Therefore, if I want to find most of the prototypes in data.raw[proto_type], it should be more efficient to go over a short list of blacklisted names than over a long list of whitelisted names. But blacklisting names only won't work as the filter would call everything with a non-matching name, including things that are of a wrong type. Do you have any suggestion how to deal with that? :-)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Post Reply

Return to “Not a bug”