Hey guys,
My mod needs to iterate through the current player units table each time a unit is added or removed from the game. However, it seems that table is not updating on certain events. The problems I can currently identify are:
-When a unit is removed from the game due to using it's last charge
-When a unit is removed from the game when combining that unit into a corps or armada
I have tested this a few different ways, but those units simply aren't being removed from the player unit table until the following turn. I have ran iterations through the unit table by hooking into UnitRemovedFromMap, UnitOperationCleared, UnitFormCorps and UnitFormArmy. The unit in question still exists in the table after each of these.
As a note, the unit table IS immediately updated in gameplay context upon losing a unit to combat, deleting a unit, and creating a unit. Also, the UnitRemovedFromMap event IS being called when using up the charges on a unit, so it seems the player unit table isn't updated directly from there.
Another observation - the updates work immediately in the UI context - just not in gameplay. When I use up a unit with charges, or combine a unit into a formation, my UI elements update immediately. The function used for counting units in the UI context is identical to the one I am using in the gameplay version.
So, my questions:
Has anyone else experienced this issue?
Is there a way to force an update of a player's unit table in gameplay context?
If not, and no other solution is apparent, can I pull data from UI context into Gameplay lua?
Thanks in advance
My mod needs to iterate through the current player units table each time a unit is added or removed from the game. However, it seems that table is not updating on certain events. The problems I can currently identify are:
-When a unit is removed from the game due to using it's last charge
-When a unit is removed from the game when combining that unit into a corps or armada
I have tested this a few different ways, but those units simply aren't being removed from the player unit table until the following turn. I have ran iterations through the unit table by hooking into UnitRemovedFromMap, UnitOperationCleared, UnitFormCorps and UnitFormArmy. The unit in question still exists in the table after each of these.
As a note, the unit table IS immediately updated in gameplay context upon losing a unit to combat, deleting a unit, and creating a unit. Also, the UnitRemovedFromMap event IS being called when using up the charges on a unit, so it seems the player unit table isn't updated directly from there.
Another observation - the updates work immediately in the UI context - just not in gameplay. When I use up a unit with charges, or combine a unit into a formation, my UI elements update immediately. The function used for counting units in the UI context is identical to the one I am using in the gameplay version.
So, my questions:
Has anyone else experienced this issue?
Is there a way to force an update of a player's unit table in gameplay context?
If not, and no other solution is apparent, can I pull data from UI context into Gameplay lua?
Thanks in advance