• 🏆 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!

[Solved] Triggers working machine

Status
Not open for further replies.
Level 2
Joined
Jun 13, 2020
Messages
16
Lets say I have two triggers that have the Events-A units starts the effect of the ability that detects the two different ability like thunder clap and war stomp.If two units cast the following spell at the exact same time,does the two trigger execute at the same time or the game will execute them in the order, like execute the war stomp trigger first then execute the thunder clap trigger. I want to knew this because my two trigger share the same variable and I scared it will cause any bug.Note that the two trigger I stated at the above are the instant triggers(not involve any wait function).
 
Last edited:

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,570
Everything happens sequentially (ordered). So similar to how Actions execute from top to bottom, triggers will be ordered as well. But there's an important exception to this rule that I discuss below.

First, an example of a trigger that relies on the order of the Actions to work properly:
  • this works
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
    • Actions
      • Set Variable Point = (Center of SomeRegion <gen>)
      • Special Effect - Create a special effect at Point using Abilities\Spells\Human\ThunderClap\ThunderClapCaster.mdl
That same trigger but with the Actions ordered incorrectly.
  • this doesnt work
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
    • Actions
      • Special Effect - Create a special effect at Point using Abilities\Spells\Human\ThunderClap\ThunderClapCaster.mdl
      • Set Variable Point = (Center of SomeRegion <gen>)
The special effect is created at Point before Point is even Set, so it doesn't know where to create the effect.

I'm sure you were aware of this already, but I figured I'd break it all down.

What's more important to mention is the situations where this DOESN'T work perfectly. You need to be careful of situations where you cause the Actions of one trigger to be added onto your current trigger. This can happen when the Actions of your trigger cause the Event of another trigger to go off. Here's an example:

This trigger makes the casting unit deal lethal damage to the target unit and then displays the name of the casting unit. Nothing wrong here, right? Not yet at least, but what would happen if that UnitVariable was used in a trigger with the Unit - A unit Dies event?
  • issue 1
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Storm Bolt
    • Actions
      • Set Variable UnitVariable = (Casting unit)
      • Unit - Cause UnitVariable to damage (Target unit of ability being cast), dealing 999999.00 damage of attack type Spells and damage type Normal
      • Game - Display to (All players) for 30.00 seconds the text: (Name of UnitVariable)
Our Cause Damage action kills the (Target unit of ability being cast) which causes the Unit - A unit Dies event to go off, which causes our next trigger to run:
  • issue 2
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • Set Variable UnitVariable = (Dying unit)
      • Game - Display to (All players) for 5.00 seconds the text: (Name of UnitVariable)
Do you see the issue? UnitVariable is going to be Set to the Dying unit IMMEDIATELY after our Cause Damage action from the first trigger. This is because the unit died during our first trigger. It's in these situations that Global Variables can cause issues.

These are the results:
  • issue 1 and 2 combined
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Storm Bolt
    • Actions
      • Set Variable UnitVariable = (Casting unit)
      • Unit - Cause UnitVariable to damage (Target unit of ability being cast), dealing 999999.00 damage of attack type Spells and damage type Normal
      • Set Variable UnitVariable = (Dying unit)
      • Game - Display to (All players) for 5.00 seconds the text: (Name of UnitVariable)
      • Game - Display to (All players) for 30.00 seconds the text: (Name of UnitVariable)
The Actions of our second trigger are inserted directly into our first trigger, and they're inserted BEFORE the first trigger has finished running.
Since UnitVariable is shared between the two triggers it's value is going to be Set twice, and in this case it's value ends up as the Dying unit.

This results in the displaying of the name of the (Dying unit) twice, while never displaying the name of the (Casting unit) despite wanting to.
 

Attachments

  • example.png
    example.png
    2.7 MB · Views: 17
Last edited:
Level 6
Joined
Dec 29, 2019
Messages
82
Lets say I have two triggers that have the Events-A units starts the effect of the ability that detects the two different ability like thunder clap and war stomp.If two units cast the following spell at the exact same time,does the two trigger execute at the same time or the game will execute them in the order, like execute the war stomp trigger first then execute the thunder clap trigger. I want to knew this because my two trigger share the same variable and I scared it will cause any bug.Note that the two trigger I stated at the above are the instant triggers(not involve any wait function).

If you are GUI map maker, then i recommend to use Hashtables for securing asynchronous function executing won't cause desync. (or variable arrays, depends on what you need to achieve)

If you are using vJASS or Lua (which i highly recommend) then local variables solve this issue for you.

BTW: it's a shame they did not implement locals for GUI users as well as tones of other usefull stuffs...
 
Level 2
Joined
Jun 13, 2020
Messages
16
If you are GUI map maker, then i recommend to use Hashtables for securing asynchronous function executing won't cause desync. (or variable arrays, depends on what you need to achieve)

If you are using vJASS or Lua (which i highly recommend) then local variables solve this issue for you.

BTW: it's a shame they did not implement locals for GUI users as well as tones of other usefull stuffs...
Thk for reply, but i think my problem had solved.About hastable and JASS,I haven't start to learn yet because they are quite confusing and hard for me( I now still trying to understand the MUI spell system btw.)
 
Status
Not open for further replies.
Top