Page 1 of 1

[0.18.8] find_enemy_units doesn't seem to work on other forces?

Posted: Tue Feb 25, 2020 4:06 am
by Oarc
I did the following to test:

Loaded up a vanilla game and ran this command:
/c game.player.print(serpent.block(game.player.surface.find_enemy_units(game.player.position, 1000)))
It found 2 entities.

Then I ran this command:
/c game.player.print(serpent.block(game.player.surface.find_enemy_units(game.player.position, 1000, "enemy")))

My expectation is that it would return 1 entity, the player character. But it returns nothing?

I found this while trying to switch from using find_nearest_enemy to find_enemy_units.
My use case is trying to find player-related units that are targets of the "enemy" force.

Re: [0.18.8] find_enemy_units doesn't seem to work on other forces?

Posted: Tue Feb 25, 2020 7:43 am
by posila
Hello. find_enemy_units searches only for entities of type "unit". Player character is not "unit", it's "character".

Re: [0.18.8] find_enemy_units doesn't seem to work on other forces?

Posted: Tue Feb 25, 2020 12:52 pm
by Oarc
Okay so it's just a documentation inconsistency then?

find_nearest_enemy says "Find nearest enemy unit".

For the record, if that's the case, I'd suggest renaming find_nearest_enemy -> find_nearest_enemy_unit

But I'd also like to request you keep find_nearest_enemy and also add a find_enemies to complement find_enemy_units. Or maybe add a filter option or something for the search.

Thanks!


Also, the examples don't seem to be properly formatted for "find_units"?

Code: Select all

 local friendly_units = game.player.surface.find_units({area = {{-10, -10},{10, 10}}, force = "player", condition = "friend")
Looks like it's missing a }?

Re: [0.18.8] find_enemy_units doesn't seem to work on other forces?

Posted: Tue Feb 25, 2020 2:58 pm
by posila
Yeah, find_nearest_enemy shouldn't say "Find nearest enemy unit" as it searches entities with force (which I don't know if we have documented anywhere as a concept)

Thanks for pointing out these documentation mistakes

Re: [0.18.8] find_enemy_units doesn't seem to work on other forces?

Posted: Tue Feb 25, 2020 3:05 pm
by Bilka
posila wrote:
Tue Feb 25, 2020 2:58 pm
Yeah, find_nearest_enemy shouldn't say "Find nearest enemy unit" as it searches entities with force (which I don't know if we have documented anywhere as a concept)
We do somewhat, on https://wiki.factorio.com/Military_units_and_structures. I updated the doc to link to the page.

Re: [0.18.8] find_enemy_units doesn't seem to work on other forces?

Posted: Tue Feb 25, 2020 7:56 pm
by Oarc
Thank you for the info and quick response!