Page 1 of 1

Undefined behavior with find_entities_filtered

Posted: Sat Sep 26, 2020 3:47 pm
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?

Re: Undefined behavior with find_entities_filtered

Posted: Sat Sep 26, 2020 4:06 pm
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.

Re: Undefined behavior with find_entities_filtered

Posted: Sat Sep 26, 2020 4:09 pm
by Honktown
ty ty