Join GitHub today
remove compiletime call in OnUnitEnterLeave #20
Alright, so I did a lot of tinkering with this, and I noticed a problem -
No matter how you use the timer for preplaced units, it's impossible to know whether you'll catch them in the group loop or via an enter event because some scripts will be initialized after OnUnitEnterLeave, some will be initialized before it, which means that, while ensuring that the unit will get processed at all costs (I moved the enum inside the nulltimer), there's a possibility of the unit triggering the enter event.
This can be fixed by moving OnUnitEnterLeave to default imports (meaning all user scripts would be initialized after it, giving us a deterministic order). But I've found a workaround without needing this.
So, in order to remove the possibility of double processing the unit (enum + event), I put everything in the null timer. After the null timer ticks:
Before the nullTimer ticks, all the system does is add adequate onEnter and onLeave functions to the trigger, so this is intended behavior.
This means that no matter where you use onEnter, as long as it is on map init, it will be processed for all existing units after nullTimer ticks.
The only downside of this now is that units won't be processed by onEnter immediately after being created during map init. To make this possible, I'd have to keep the track of processed units which would create some overhead. Should I do this? I'd just have to add a group that contains all "prepared" units and make sure I don't prepare units already in that group.
Also, DamageDetection didn't work for non-preplaced units, because it used the old onEnter semantics which used Filtered unit for some reason. Now it simply adds a working onEnter action, and works for both preplaced and units added after init and after the null timer.