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

[Trigger] Local Variables?

Status
Not open for further replies.
Level 7
Joined
Oct 20, 2010
Messages
182
I have been trying to test this to no avail:

If a trigger can cause itself to run, will it add it to the end of the queue or first finish the trigger being run? For the following code, will armyReal be overwritten before the first set of "pick every unit" completes? I hope this question is as clear as I'm trying to make it.


  • Example
    • Events
      • Game - DamageEvent becomes Equal to 1.00
    • Conditions
      • (Random integer number between 1 and 4) Equal to 1
      • DamageEventAttackT Equal to 5
    • Actions
      • Set VariableSet loc = (Position of DamageEventSource)
      • Set VariableSet armyReal = (Random real number between 10.00 and 20.00)
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units within 300.00 of loc) and do (Actions)
        • Loop - Actions
          • Unit - Cause DamageEventSource to damage (Picked unit), dealing armyReal damage of attack type Normal and damage type Normal
      • Custom script: call RemoveLocation(udg_loc)
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,570
I'm pretty sure Bribe's damage engine is completely recursion proof so you have nothing to worry about.

I THINK what it does is delay the Damage Events inside of your Loop so that they run after this trigger is finished. But maybe I'm misunderstanding it...

Regardless, I think the condition DamageEventAttackT Equal to 5 would prevent this issue anyway.

The loc variable is concerning though. If it's some generic variable that you use elsewhere I'd be careful since it could easily cause a memory leak. How about creating a set of variables dedicated solely to Damage Events?
 
Last edited:
Level 7
Joined
Oct 20, 2010
Messages
182
1. My bad, I was editing this after pasting it: DamageEventAttackT Equal to 5 is chaos damage, but it should be normal damage. So this code is able to trigger itself (at least that's the intention).

2. How would the loc leak if removed? Sorry, I'm not sure how so I am curious in what ways this can go wrong.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,570
1. My bad, I was editing this after pasting it: DamageEventAttackT Equal to 5 is chaos damage, but it should be normal damage. So this code is able to trigger itself (at least that's the intention).

2. How would the loc leak if removed? Sorry, I'm not sure how so I am curious in what ways this can go wrong.
1) That's fine I think because it's still recursion proof. At least, if it works the way I think it does.

2) An example: TriggerA sets loc and then deals damage to a unit before removing loc. TriggerB uses a Damage Event which goes off in response to the damage from TriggerA. The problem: TriggerB also sets loc, which causes a memory leak since loc has been set twice in a row now without getting removed.

Here's an example you can test yourself:
  • Untitled Trigger 001
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • Unit - Cause Paladin 0021 <gen> to damage Paladin 0021 <gen>, dealing 5.00 damage of attack type Spells and damage type Normal
      • Game - Display to (All players) for 30.00 seconds the text: A
  • Untitled Trigger 002
    • Events
      • Unit - Paladin 0021 <gen> Takes damage
    • Conditions
    • Actions
      • Game - Display to (All players) for 30.00 seconds the text: B
You'll see when you press escape (skip cinematic) the text message "B" is displayed before "A".

This means that if both triggers were to set loc, with the first trigger setting it BEFORE damage is dealt and removing it AFTER damage was dealt, loc would leak.
 
Last edited:
Level 7
Joined
Oct 20, 2010
Messages
182
Ah I see. You mentioned using one set of variables for damage event triggers. Would loc be recursive if a damage action triggered another trigger?

  • Trigger1
    • Events
      • Game - DamageEvent becomes Equal to 1.00
    • Conditions
      • IsDamageAttack Equal to True
    • Actions
      • Set VariableSet loc = (Position of DamageEventSource)
      • Game - Display to (All players) the text: 1
      • Unit - Cause DamageEventSource to damage DamageEventTarget, dealing 10.00 damage of attack type Chaos and damage type Normal
      • Game - Display to (All players) the text: 2
      • Custom script: call RemoveLocation(udg_loc)
  • Trigger2
    • Events
      • Game - DamageEvent becomes Equal to 1.00
    • Conditions
      • DamageEventAttackT Equal to 5
    • Actions
      • Game - Display to (All players) the text: 3
      • Set VariableSet loc = (Position of DamageEventSource)
      • Custom script: call RemoveLocation(udg_loc)
When I use these triggers in game, it goes 1 2 3. This seems to imply to me that a trigger finishes running first, with all instances of cause damage that were initiated in it to occur after its finished?

However when I swap trigger1 with Player skips a cinematic instead of damageevent, it goes 1 3 2.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,570
Ah I see. You mentioned using one set of variables for damage event triggers. Would loc be recursive if a damage action triggered another trigger?

  • Trigger1
    • Events
      • Game - DamageEvent becomes Equal to 1.00
    • Conditions
      • IsDamageAttack Equal to True
    • Actions
      • Set VariableSet loc = (Position of DamageEventSource)
      • Game - Display to (All players) the text: 1
      • Unit - Cause DamageEventSource to damage DamageEventTarget, dealing 10.00 damage of attack type Chaos and damage type Normal
      • Game - Display to (All players) the text: 2
      • Custom script: call RemoveLocation(udg_loc)
  • Trigger2
    • Events
      • Game - DamageEvent becomes Equal to 1.00
    • Conditions
      • DamageEventAttackT Equal to 5
    • Actions
      • Game - Display to (All players) the text: 3
      • Set VariableSet loc = (Position of DamageEventSource)
      • Custom script: call RemoveLocation(udg_loc)
When I use these triggers in game, it goes 1 2 3. This seems to imply to me that a trigger finishes running first, with all instances of cause damage that were initiated in it to occur after its finished?

However when I swap trigger1 with Player skips a cinematic instead of damageevent, it goes 1 3 2.
Yeah, if it goes 1, 2, 3 then that means the triggers are being separated and ordered properly, and I assume that's thanks to the Damage Engine.
 
Status
Not open for further replies.
Top