Knighttime
Prince
- Joined
- Sep 20, 2002
- Messages
- 364
I'm frustrated by a gameplay issue resulting from Lua events, and wondering if someone out there knows a better way to handle this.
I have some code that is called when a unit is activated -- meaning, it is run from the onActivateUnit() trigger -- which evaluates the newly-activated unit and, in some conditions, determines that it should actually be deleted immediately, rather than be allowed to have its turn and take any action. But when I do this, using civ.deleteUnit(), the game seems to flip from "Move Pieces" mode into "View Pieces" mode so that no unit is really active at all, until I press "v".
Furthermore this situation can happen to multiple units in a row, so it leads to a lot of "v" being pressed until I end up with a unit that is actually allowed to take its turn -- enough that it gets annoying.
I experimented with finding the next unit that I want to activate, rather than relying on the game to determine this, and calling nextUnit:activate() first, before I call civ.deleteUnit(). But that doesn't seem to make any difference -- I'm still stuck in the wrong mode and have to press "v" to actually make nextUnit activate and ready to move.
I'm not aware of any TOTPP function that can switch the UI mode programmatically either.
My "last resort" solution would be to call nextUnit:activate(), but not call civ.deleteUnit() at that time, and instead populate a table or variable with the ID of the unit to be deleted. Then within onActivateUnit(), I could add code to see if that table or variable contains any IDs, and if so, delete the unit(s) at that point -- in other words, never deleting a unit while within the onActivateUnit() trigger for that unit, but always waiting until I'm within that trigger for another unit. This seems like such a hackish workaround that I thought I would post the problem here first, before I try going down that road.
Can anyone point me to a scenario or bit of code that provides a way to delete the active unit and immediately and seamlessly activate another one, without the mode toggle problem?
I have some code that is called when a unit is activated -- meaning, it is run from the onActivateUnit() trigger -- which evaluates the newly-activated unit and, in some conditions, determines that it should actually be deleted immediately, rather than be allowed to have its turn and take any action. But when I do this, using civ.deleteUnit(), the game seems to flip from "Move Pieces" mode into "View Pieces" mode so that no unit is really active at all, until I press "v".
Furthermore this situation can happen to multiple units in a row, so it leads to a lot of "v" being pressed until I end up with a unit that is actually allowed to take its turn -- enough that it gets annoying.
I experimented with finding the next unit that I want to activate, rather than relying on the game to determine this, and calling nextUnit:activate() first, before I call civ.deleteUnit(). But that doesn't seem to make any difference -- I'm still stuck in the wrong mode and have to press "v" to actually make nextUnit activate and ready to move.
I'm not aware of any TOTPP function that can switch the UI mode programmatically either.
My "last resort" solution would be to call nextUnit:activate(), but not call civ.deleteUnit() at that time, and instead populate a table or variable with the ID of the unit to be deleted. Then within onActivateUnit(), I could add code to see if that table or variable contains any IDs, and if so, delete the unit(s) at that point -- in other words, never deleting a unit while within the onActivateUnit() trigger for that unit, but always waiting until I'm within that trigger for another unit. This seems like such a hackish workaround that I thought I would post the problem here first, before I try going down that road.
Can anyone point me to a scenario or bit of code that provides a way to delete the active unit and immediately and seamlessly activate another one, without the mode toggle problem?