[Solved] Loop Breaks due to another loop created at unit death.

Status
Not open for further replies.
Hello thanks for stopping by. Here is my problem:

  • Unit Group - Pick every unit in (Units within SpellAoeSize[GenericLoopCount] of SpellTargetPoint[GenericLoopCount].) and do (Actions)
    • Loop - Actions
      • (debug: Display name of OrginalCaster[GenericLoopCount]) = Mage
      • Unit - Cause OriginalCaster[GenericLoopCount] to damage (Picked unit), dealing 400 damage of attack type Spells and damage type Normal
      • (debug: Display name of OrginalCaster[GenericLoopCount]) = Null
This looks pretty simple to me, but only the very first iteration works. Immediately after the Unit Damages a Unit command. All 3 variables fail, spellsize goes from 250 to 0. Target Point and original caster are lost. This trigger is happening within a loop that counts using the GenericLoopCount integer. Version is Reforged Beta.
 
Note: Doing this fixed the problem. But could someone still explain to me why the first one wouldn't work?
  • Set VariableSet TempInt = GenericLoopCount
  • Unit Group - Pick every unit in (Units within SpellAoeSize[TempInt] of SpellTargetPoint[TempInt].) and do (Actions)
    • Loop - Actions
      • Unit - Cause OriginalCaster[TempInt] to damage (Picked unit), dealing 400 damage of attack type Spells and damage type Normal
 
I believe even if there was another trigger that would interject it would not do so while enumerating the unit group, but rather would queue itself for processing afterward.
Incorrect. Triggers that cause other triggers to fire will be immediately interrupted by the secondary trigger and will only resume once that secondary trigger (and any further triggers it may spawn) finishes or hits a wait.
 
Yeah that makes sense. Not sure why I thought otherwise. Just to make sure for clarification the following would be true, right?
Trigger A: (Unit enters Region: Square -> Kill Unit Bob)
Trigger B: (Pick All units in 6 unit group -> Move unit to random point in Region Square, then kill that unit)
Conclusion: Bob will be the 2nd unit to die among the 7 in the map.
 
Hmm I just ran this through a loop with that knowledge and it does indeed break it:
  • Unit Dies
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • For each (Integer GenericLoopCount) from 1 to 5, do (Actions)
        • Loop - Actions
          • Special Effect - Create a special effect at (Center of (Playable map area)) using Abilities\Spells\Human\ThunderClap\ThunderClapCaster.mdl
  • Kill All 5 Units
    • Events
      • Time - Elapsed game time is 5.00 seconds
    • Conditions
    • Actions
      • For each (Integer GenericLoopCount) from 1 to 5, do (Actions)
        • Loop - Actions
          • Unit - Kill Unit[GenericLoopCount]
          • Game - Display to (All players) the text: (String(GenericLoopCount))
While this wasn't my original question this is rather critical knowledge. I will have to make sure to use unrelated loop counts in areas where this could occur, Pyrogasm, do you happen to have any optimal experience to share on this matter? For example your best practice for avoiding this Loop Ruiner?
 
Regarding my first post: This actually did solve it. There was a Unit Dies event that used GenericLoopCount, so if that spell was killing a unit, which in this case it did. It would kill the first unit, move to the unit died trigger scramble GenericLoopCount's actual value by running a new loop with it, then return to the unit damaging trigger with GenericLoopCount now represented with an irrelevant position.
 
Status
Not open for further replies.
Back
Top