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

Place to get help with not working mods / modding interface.
Post Reply
Oarc
Fast Inserter
Fast Inserter
Posts: 100
Joined: Sun Sep 18, 2016 2:04 pm
Contact:

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

Post 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.

posila
Factorio Staff
Factorio Staff
Posts: 5202
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

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

Post by posila »

Hello. find_enemy_units searches only for entities of type "unit". Player character is not "unit", it's "character".

Oarc
Fast Inserter
Fast Inserter
Posts: 100
Joined: Sun Sep 18, 2016 2:04 pm
Contact:

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

Post 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 }?

posila
Factorio Staff
Factorio Staff
Posts: 5202
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

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

Post 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

Bilka
Factorio Staff
Factorio Staff
Posts: 3138
Joined: Sat Aug 13, 2016 9:20 am
Contact:

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

Post 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.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

Oarc
Fast Inserter
Fast Inserter
Posts: 100
Joined: Sun Sep 18, 2016 2:04 pm
Contact:

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

Post by Oarc »

Thank you for the info and quick response!

Post Reply

Return to “Modding help”