Page 1 of 1
[Solved] What will happen to entities when merging two forces?
Posted: Tue Jun 10, 2025 1:19 am
by yaim904
I want to program the event
on_forces_merged, but I don't know what happens with the entities in forces to be eliminated, are they destroyed? are they kept and the force is changed? or what happens?
I know it's a simple question, but I don't know of an event that merges forces for testing.
Re: What will happen to entities when merging two forces?
Posted: Tue Jun 10, 2025 1:53 am
by robot256
All the entities in the "source" force should have their force changed to the "destination" force before the source force is deleted.
Re: What will happen to entities when merging two forces?
Posted: Tue Jun 10, 2025 2:30 am
by yaim904
robot256 wrote: Tue Jun 10, 2025 1:53 am
Thanks for the answer
I think the message got lost in translation.
The entities will be destroyed?
I have to change the force on the entities?
Please be more detailed, I don't know much about the force.
Re: What will happen to entities when merging two forces?
Posted: Tue Jun 10, 2025 2:50 am
by robot256
The force parameter of each entity is changed automatically by the game during the "game.merge_forces" function call. The entities continue to exist and the same LuaEntity references are still valid. You do not have to do anything, except any special logic that you need to run to make your mod work correctly when entities change what force they are in.
I used the word "should" because I once observed a weird case where entities were left with an invalid force parameter, but I couldn't replicate it.
Re: What will happen to entities when merging two forces?
Posted: Tue Jun 10, 2025 2:56 am
by yaim904
robot256 wrote: Tue Jun 10, 2025 2:50 am
Now I understand, thanks for the clarification.
Out of curiosity, at what point do the forces combine? I can't imagine a scenario where two forces merge.
Re: [Solved] What will happen to entities when merging two forces?
Posted: Tue Jun 10, 2025 3:01 am
by robot256
1. It's impossible to delete forces. You can only merge them. You can choose to delete all the entities on the unwanted force before you merge them, or you can allow them to be reassigned.
2. Many mods make hidden forces to achieve certain things. The mod that lets you make overlapping independent roboport "channels" is one. The roboports for each channel are assigned a different force so the robots stay separated. When you remove a previously added robotport channel, it has to delete the hidden force by merging it with the player force.