• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] EVENT_UNIT_DAMAGED firing mid function?

Status
Not open for further replies.
Level 2
Joined
Nov 29, 2021
Messages
8
Alright, I just fixed a strange bug.

I had a trigger that would use a global to a.) deal damage and b.) create a floating text.
There was nothing between both function calls. They were back to back.
Yet somehow the the damage would be dealt but the floating text would always be 0.

Turns out the damage would cause another trigger with "EVENT_UNIT_DAMAGED" to fire and that function was using the same global.

Until now I was under the believe that event handlers firing mid tick would get pushed to the end of the stack or atleast behind the current function, but it looks like they get put on top of it instead.
Meaning that the game would execute the first half of my function, then an entirely different function that I didn't directly call and then the second half of my starting function.

Now my question, does it work like that for all Event Handlers? Do they just work like function calls?
If yes, why haven't I seen anyone talking about it?
I have been mapping (and lurking on here) for years now and this seems like the kind of bug new map makers would run into all the time.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,555
It works like that for a select few Events. The function or Action of one trigger can cause the Event of another trigger to happen, and instead of it being queued like you described, the Actions are inserted directly into the first trigger. These inserted actions are positioned directly below the Action that put them there.
I believe you can see this happen with the "A unit dies" Event when Killing a unit during an ongoing trigger.

That's why it's best not to share global variables between triggers unless you're fully aware of these inconsistencies and edge cases. Often times restructuring the Actions of your trigger can avoid this issue, for example in your case you could probably Deal the damage near the end of the trigger after everything else that uses said variable has occurred to avoid the issue entirely.
 
Last edited:
Level 2
Joined
Nov 29, 2021
Messages
8
Cool, learned something new today.

Most of all that I was extremly lucky with my Damage Detection and Display Systems, since I only used locals in them.
 
Status
Not open for further replies.
Top