Undefined behavior with find_entities_filtered

Post Reply
Honktown
Smart Inserter
Smart Inserter
Posts: 1025
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Undefined behavior with find_entities_filtered

Post by Honktown »

Example code:

Code: Select all

        local path = self.ent.surface.find_entities_filtered{position=self.ent.position, type="resource", limit=1}
The code is intended to find a resource that's at the same position as an entity. It works, but the behavior isn't defined in the api:

Code: Select all

Find entities of given type or name in a given area.

If no filters (name, type, or force) are given, returns all entities in the search area. If multiple filters are specified, returns only entities matching all given filters.

If no area and no position are given, then the entire surface is searched. If both area and position are specified, returns only entities matching the position. If position and radius are given, returns only entities within that radius of the position.
Stated one way, with only position defined, the last paragraph doesn't describe what 'shall' happen. Stated another way, an area behavior (no area no position, area+position, position+radius) was not given, so I might expect the function to error, or even search the whole map (no defined area behavior -> search whole map) despite a position being given.

It is a bit pedantic, but can a clarification be given as to whether this behavior is reliable?
I have mods! I guess!
Link

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5150
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Undefined behavior with find_entities_filtered

Post by Klonan »

Updated for the next release:

Code: Select all

//? If no area or position are given, then the entire surface is searched.
//? If position is given, returns entities colliding with that position (i.e the given position is within the entity's collision box).
//? If position and radius are given, returns entities in that radius of the position.
//? If area is specified, returns entities colliding with that area.

Honktown
Smart Inserter
Smart Inserter
Posts: 1025
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: Undefined behavior with find_entities_filtered

Post by Honktown »

ty ty
I have mods! I guess!
Link

Post Reply

Return to “Implemented mod requests”