Wait and Triggering unit. MUI?

Level 3
Joined
Jun 6, 2024
Messages
12
I need to make sure if this code is safe to play among many players, and I'm a bit confused because I've read different versions regarding triggering units and waits. Is the variable that holds the Triggering unit local to each trigger execution/instance? Meaning, if many triggers are executed simultaneously, will each one remember its Triggering unit? In other words, is this code safe in a multiplayer context?


  • Events
    • Unit - A unit Dies
  • Conditions
    • ((Triggering unit) is A Hero) Equal to True
  • Actions
    • Wait 6.00 seconds
    • Game - Display to (All players) the text: (((Name of (Triggering unit)) + ( the + (Proper name of (Triggering unit)))) + has fallen.)
 
Yes, your code is MUI and is safe to use in the case you described. The "Triggering unit" event response is local to the "thread" of execution (and to any new threads spawned by that thread).

One important thing to note though is that "MUI" (Multi-unit instanceability) isn't so much about multiplayer. It's more about having multiple units triggering some code and making sure they don't conflict with one another. I have a pretty concise explanation here if you're curious!

So consider this code:
  • DisplayName
    • Events
      • Unit - A unit Is issued an order targeting a point
    • Conditions
    • Actions
      • Wait 5.00 seconds
      • Game - Display to (All players) the text: (Name of (Triggering unit))
This is MUI since it is just dealing with local values (triggering unit). So if I put this in a test map, and then I issue an order to a footman and then a peasant, the game will display "Footman" then "Peasant" correctly. But if I were to introduce a global variable:
  • DisplayName
    • Events
      • Unit - A unit Is issued an order targeting a point
    • Conditions
    • Actions
      • Set VariableSet OrderedUnit = (Triggering unit)
      • Wait 5.00 seconds
      • Game - Display to (All players) the text: (Name of OrderedUnit)
Then it is no longer MUI. If I run the same scenario above, it'll display "Peasant" then "Peasant", since the Peasant now occupies the global value of OrderedUnit.

So ultimately your code is safe if you stick with local values--and if you ever need to test it, you can just test it out with multiple units. No need to test it in multiplayer!

If you want to do more complex triggers, then you can use techniques mentioned in the tutorial above^ (e.g. dynamic indexing) so that you can run timed code safely no matter how many units you shove into it!
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,860
Here's a decent list of what's considered "local" and "global". Unfortunately, not all Event Responses were created equally :p

Also, Waits are imprecise when playing online since they need to be synced between players. This can be acceptable in some cases but is generally not ideal. When you want precise control over your "timed effects" you should rely on Timers or the Periodic Interval Event, which ties into what Purge said about Dynamic Indexing.
 
Last edited:
Top