• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Trigger] Unit Group Array Bug

Status
Not open for further replies.
Level 1
Joined
Aug 30, 2011
Messages
3
Hello, in my spell I pick units around a point and then damage them and then adding them to another unit group to prevent that they would be damaged again. But it works only for the first time...it damages all units just once....second time it damages units multiple times... I can't solve this problem by myslef, because i really don't know why this happens. Perhaps, there are things that are not professional.. this is my first larger spell. Please help me to figure it out. Thanks.

  • Nature Spirits
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Nature Spirits (Dummy Spell)
    • Actions
      • If (NSTimes Equal to 5000) then do (Set NSTimes = 1) else do (Set NSTimes = (NSTimes + 1))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in NSGroup[0]) Equal to 0
        • Then - Actions
          • Trigger - Turn on Nature Spirits Loop <gen>
        • Else - Actions
          • Do nothing
      • Set NSCaster[NSTimes] = (Casting unit)
      • Set NSPoint[0] = (Position of NSCaster[NSTimes])
      • Set NSPoint[1] = (Target point of ability being cast)
      • Set NSAngle[0] = (Angle from NSPoint[0] to NSPoint[1])
      • Set NSPoint[11] = (NSPoint[0] offset by 40.00 towards NSAngle[0] degrees)
      • Unit - Create 1 NSDummy for (Owner of NSCaster[NSTimes]) at NSPoint[11] facing NSAngle[0] degrees
      • Hashtable - Save Handle Of(Last created unit) as 0 of (Key (Last created unit)) in NSHash
      • Hashtable - Save 25.00 as 1 of (Key (Last created unit)) in NSHash
      • Hashtable - Save False as 2 of (Key (Last created unit)) in NSHash
      • Hashtable - Save 40 as 3 of (Key (Last created unit)) in NSHash
      • Hashtable - Save False as 4 of (Key (Last created unit)) in NSHash
      • Hashtable - Save NSAngle[0] as 5 of (Key (Last created unit)) in NSHash
      • Hashtable - Save Handle OfNSPoint[0] as 6 of (Key (Last created unit)) in NSHash
      • Unit Group - Add (Last created unit) to NSGroup[0]
      • Set NSPoint[12] = (NSPoint[0] offset by 43.29 towards (NSAngle[0] + 22.50) degrees)
      • Unit - Create 1 NSDummy 2 for (Owner of NSCaster[NSTimes]) at NSPoint[12] facing NSAngle[0] degrees
      • Hashtable - Save Handle Of(Last created unit) as 0 of (Key (Last created unit)) in NSHash
      • Hashtable - Save 95.00 as 1 of (Key (Last created unit)) in NSHash
      • Hashtable - Save True as 2 of (Key (Last created unit)) in NSHash
      • Hashtable - Save 16 as 3 of (Key (Last created unit)) in NSHash
      • Hashtable - Save True as 4 of (Key (Last created unit)) in NSHash
      • Hashtable - Save NSAngle[0] as 5 of (Key (Last created unit)) in NSHash
      • Hashtable - Save Handle OfNSPoint[0] as 6 of (Key (Last created unit)) in NSHash
      • Unit Group - Add (Last created unit) to NSGroup[0]
      • Set NSPoint[13] = (NSPoint[0] offset by 43.29 towards (NSAngle[0] - 22.50) degrees)
      • Unit - Create 1 NSDummy 3 for (Owner of NSCaster[NSTimes]) at NSPoint[13] facing NSAngle[0] degrees
      • Hashtable - Save Handle Of(Last created unit) as 0 of (Key (Last created unit)) in NSHash
      • Hashtable - Save 95.00 as 1 of (Key (Last created unit)) in NSHash
      • Hashtable - Save False as 2 of (Key (Last created unit)) in NSHash
      • Hashtable - Save 64 as 3 of (Key (Last created unit)) in NSHash
      • Hashtable - Save True as 4 of (Key (Last created unit)) in NSHash
      • Hashtable - Save NSAngle[0] as 5 of (Key (Last created unit)) in NSHash
      • Hashtable - Save Handle OfNSPoint[0] as 6 of (Key (Last created unit)) in NSHash
      • Unit Group - Add (Last created unit) to NSGroup[0]
      • Set NSPoint[14] = (NSPoint[0] offset by 40.00 towards NSAngle[0] degrees)
      • Unit - Create 1 Dummy 1 for (Owner of NSCaster[NSTimes]) at NSPoint[14] facing NSAngle[0] degrees
      • Set NSDistance[NSTimes] = 40.00
      • Hashtable - Save Handle Of(Last created unit) as 0 of (Key (Last created unit)) in NSHash
      • Hashtable - Save NSAngle[0] as 1 of (Key (Last created unit)) in NSHash
      • Hashtable - Save NSTimes as 2 of (Key (Last created unit)) in NSHash
      • Hashtable - Save NSDistance[NSTimes] as 3 of (Key (Last created unit)) in NSHash
      • Hashtable - Save Handle OfNSPoint[0] as 4 of (Key (Last created unit)) in NSHash
      • Unit Group - Add (Last created unit) to NSGroup[1]
      • Custom script: call RemoveLocation(udg_NSPoint[1])
      • Custom script: call RemoveLocation(udg_NSPoint[11])
      • Custom script: call RemoveLocation(udg_NSPoint[12])
      • Custom script: call RemoveLocation(udg_NSPoint[13])
      • Custom script: call RemoveLocation(udg_NSPoint[14])
  • Nature Spirits Loop
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in NSGroup[0] and do (Actions)
        • Loop - Actions
          • Set NSUnit[0] = (Load 0 of (Key (Picked unit)) in NSHash)
          • Set NSHeight = (Load 1 of (Key (Picked unit)) from NSHash)
          • Set NSHeightCheck = (Load 2 of (Key (Picked unit)) from NSHash)
          • Set NSRange = (Load 3 of (Key (Picked unit)) from NSHash)
          • Set NSRangeCheck = (Load 4 of (Key (Picked unit)) from NSHash)
          • Set NSAngle[1] = (Load 5 of (Key (Picked unit)) from NSHash)
          • Set NSPoint[3] = (Load 6 of (Key (Picked unit)) in NSHash)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Or - Any (Conditions) are true
                • Conditions
                  • NSHeightCheck Equal to True
                  • NSHeight Equal to 25.00
            • Then - Actions
              • Set NSHeightCheck = True
              • Set NSHeight = (NSHeight + 10.00)
              • Hashtable - Save NSHeight as 1 of (Key (Picked unit)) in NSHash
              • Animation - Change NSUnit[0] flying height to NSHeight at 0.00
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • NSHeight Equal to 125.00
                • Then - Actions
                  • Set NSHeightCheck = False
                • Else - Actions
                  • Do nothing
              • Hashtable - Save NSHeightCheck as 2 of (Key (Picked unit)) in NSHash
            • Else - Actions
              • Set NSHeight = (NSHeight - 10.00)
              • Hashtable - Save NSHeight as 1 of (Key (Picked unit)) in NSHash
              • Animation - Change NSUnit[0] flying height to NSHeight at 300.00
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Or - Any (Conditions) are true
                • Conditions
                  • NSRange Equal to 0
                  • NSRangeCheck Equal to True
            • Then - Actions
              • Set NSRangeCheck = True
              • Set NSRange = (NSRange + 8)
              • Hashtable - Save NSRange as 3 of (Key (Picked unit)) in NSHash
              • Set NSPoint[4] = (Position of NSUnit[0])
              • Set NSPoint[5] = (NSPoint[4] offset by 35.90 towards (NSAngle[1] - 12.87) degrees)
              • Unit - Move NSUnit[0] instantly to NSPoint[5]
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • NSRange Equal to 80
                • Then - Actions
                  • Set NSRangeCheck = False
                • Else - Actions
                  • Do nothing
              • Hashtable - Save NSRangeCheck as 4 of (Key (Picked unit)) in NSHash
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Distance between NSPoint[3] and NSPoint[5]) Greater than or equal to 1480.00
                • Then - Actions
                  • Special Effect - Create a special effect at NSPoint[5] using Abilities\Spells\NightElf\FaerieDragonInvis\FaerieDragon_Invis.mdl
                  • Special Effect - Destroy (Last created special effect)
                  • Unit - Add a 0.10 second Generic expiration timer to NSUnit[0]
                  • Unit Group - Remove NSUnit[0] from NSGroup[0]
                  • Hashtable - Clear all child hashtables of child (Key (Picked unit)) in NSHash
                • Else - Actions
                  • Do nothing
              • Custom script: call RemoveLocation(udg_NSPoint[4])
              • Custom script: call RemoveLocation(udg_NSPoint[5])
            • Else - Actions
              • Set NSRange = (NSRange - 8)
              • Hashtable - Save NSRange as 3 of (Key (Picked unit)) in NSHash
              • Set NSPoint[4] = (Position of NSUnit[0])
              • Set NSPoint[5] = (NSPoint[4] offset by 35.90 towards (NSAngle[1] + 12.87) degrees)
              • Unit - Move NSUnit[0] instantly to NSPoint[5]
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Distance between NSPoint[3] and NSPoint[5]) Greater than or equal to 1480.00
                • Then - Actions
                  • Special Effect - Create a special effect at NSPoint[5] using Abilities\Spells\NightElf\FaerieDragonInvis\FaerieDragon_Invis.mdl
                  • Special Effect - Destroy (Last created special effect)
                  • Unit - Add a 0.10 second Generic expiration timer to NSUnit[0]
                  • Unit Group - Remove NSUnit[0] from NSGroup[0]
                  • Hashtable - Clear all child hashtables of child (Key (Picked unit)) in NSHash
                • Else - Actions
                  • Do nothing
              • Custom script: call RemoveLocation(udg_NSPoint[4])
              • Custom script: call RemoveLocation(udg_NSPoint[5])
      • Unit Group - Pick every unit in NSGroup[1] and do (Actions)
        • Loop - Actions
          • Set NSUnit[0] = (Load 0 of (Key (Picked unit)) in NSHash)
          • Set NSAngle[1] = (Load 1 of (Key (Picked unit)) from NSHash)
          • Set NS = (Load 2 of (Key (Picked unit)) from NSHash)
          • Set NSDistance[NS] = (Load 3 of (Key (Picked unit)) from NSHash)
          • Set NSPoint[3] = (Load 4 of (Key (Picked unit)) in NSHash)
          • Set NSPoint[4] = (NSPoint[3] offset by NSDistance[NS] towards NSAngle[1] degrees)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Or - Any (Conditions) are true
                • Conditions
                  • NSDistance[NS] Equal to 40.00
                  • NSDistance[NS] Equal to 180.00
                  • NSDistance[NS] Equal to 320.00
                  • NSDistance[NS] Equal to 460.00
                  • NSDistance[NS] Equal to 600.00
                  • NSDistance[NS] Equal to 740.00
                  • NSDistance[NS] Equal to 880.00
                  • NSDistance[NS] Equal to 1020.00
                  • NSDistance[NS] Equal to 1160.00
                  • NSDistance[NS] Equal to 1300.00
                  • NSDistance[NS] Equal to 1440.00
            • Then - Actions
              • Set NSGroup[2] = (Units within 140.00 of NSPoint[4] matching ((((Matching unit) belongs to an ally of (Owner of NSCaster[NS])) Equal to False) and ((((Matching unit) is A structure) Equal to False) and ((((Matching unit) is Mechanical) Equal to False) and ((((Matching unit) i
              • Unit Group - Pick every unit in NSGroup[2] and do (Actions)
                • Loop - Actions
                  • Set NSPoint[5] = (Position of (Picked unit))
                  • Unit - Create 1 Dummy 1 for (Owner of NSCaster[NS]) at NSPoint[5] facing Default building facing degrees
                  • Set NSUnit[1] = (Last created unit)
                  • Unit - Cause NSUnit[1] to damage (Picked unit), dealing ((Real((Level of Nature Spirits (Dummy Spell) for NSCaster[NS]))) x 100.00) damage of attack type Spells and damage type Enhanced
                  • Unit - Add Slow (Nature Spirits) to NSUnit[1]
                  • Unit - Set level of Slow (Nature Spirits) for NSUnit[1] to (Level of Nature Spirits (Dummy Spell) for NSCaster[NS])
                  • Special Effect - Create a special effect at NSPoint[5] using Abilities\Spells\NightElf\ManaBurn\ManaBurnTarget.mdl
                  • Special Effect - Destroy (Last created special effect)
                  • Unit - Order NSUnit[1] to Human Sorceress - Slow (Picked unit)
                  • Unit - Add a 2.00 second Generic expiration timer to NSUnit[1]
                  • Unit Group - Add (Picked unit) to NSCheckGroup[NS]
                  • Custom script: call RemoveLocation(udg_NSPoint[5])
              • Custom script: call DestroyGroup(udg_NSGroup[2])
              • Set NSGroup[2] = (Units within 145.00 of NSPoint[4] matching ((((Matching unit) belongs to an ally of (Owner of NSCaster[NS])) Equal to True) and ((((Matching unit) is alive) Equal to True) and ((((Matching unit) is A structure) Equal to False) and ((((Matching unit) is Mecha
              • Unit Group - Pick every unit in NSGroup[2] and do (Actions)
                • Loop - Actions
                  • Set NSPoint[5] = (Position of (Picked unit))
                  • Unit - Create 1 Dummy 1 for (Owner of NSCaster[NS]) at NSPoint[5] facing Default building facing degrees
                  • Set NSUnit[1] = (Last created unit)
                  • Unit - Add Heal (Nature Spirits) to NSUnit[1]
                  • Unit - Set level of Heal (Nature Spirits) for NSUnit[1] to (Level of Nature Spirits (Dummy Spell) for NSCaster[NS])
                  • Unit - Order NSUnit[1] to Human Paladin - Holy Light (Picked unit)
                  • Special Effect - Create a special effect at NSPoint[5] using Abilities\Spells\Items\ResourceItems\ResourceEffectTarget.mdl
                  • Special Effect - Destroy (Last created special effect)
                  • Unit - Add a 2.00 second Generic expiration timer to NSUnit[1]
                  • Unit Group - Add (Picked unit) to NSCheckGroup[NS]
                  • Custom script: call RemoveLocation(udg_NSPoint[5])
              • Custom script: call DestroyGroup(udg_NSGroup[2])
              • Custom script: call RemoveLocation(udg_NSPoint[4])
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • NSDistance[NS] Equal to 1510.00
                • Then - Actions
                  • Unit - Add a 0.10 second Generic expiration timer to NSUnit[0]
                  • Unit Group - Remove all units from NSCheckGroup[NS]
                  • Unit Group - Remove NSUnit[0] from NSGroup[1]
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Number of units in NSGroup[1]) Equal to 0
                    • Then - Actions
                      • Trigger - Turn off (This trigger)
                    • Else - Actions
                      • Do nothing
                  • Hashtable - Clear all child hashtables of child (Key (Picked unit)) in NSHash
                  • Custom script: call RemoveLocation(udg_NSPoint[3])
                • Else - Actions
                  • Do nothing
              • Custom script: call RemoveLocation(udg_NSPoint[4])
          • Set NSDistance[NS] = (NSDistance[NS] + 35.00)
          • Hashtable - Save NSDistance[NS] as 3 of (Key (Picked unit)) in NSHash
 
Last edited:
Level 1
Joined
Aug 30, 2011
Messages
3
Ok. Thank you, but I'm not sure where exactly use this and please explain me what exactly it does.. I don't want to put in triggers which I don't understand.
 
  • For each (IntegerA) from 0 to 2, do (Actions)
    • Loop - Actions
      • Custom script: set udg_NSGroup[bj_forLoopAIndex] = CreateGroup()
I think this could be changed to:

  • Custom script: set udg_NSGroup[0] = CreateGroup()
  • Custom script: set udg_NSGroup[1] = CreateGroup()
  • Custom script: set udg_NSGroup[2] = CreateGroup()
Since you're only doing this thrice :p

You can still use the loop though, but this is slightly more efficient cause it does the actions directly and avoids 3 extra operations and 3 evaluations :p
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
For some variable types (unit group, timer, dialog..) there is an initial value. If you create a unit group variable in the variable editor, a unit group is created for it at map initialization.

For arrays, indexes from 0 to initial size are automatically created.

Arrays have default initial size of 1. That means, for example, that for unit group arrays with initial size of 1, indexes 0 and 1 are initialized at map initialization.

If one then creates groups for those indexes without destroying the existing ones, leaks are caused.
 
Level 1
Joined
Aug 30, 2011
Messages
3
So I add
  • Custom script: set udg_NSGroup[0] = CreateGroup()
  • Custom script: set udg_NSGroup[1] = CreateGroup()
  • Custom script: set udg_NSGroup[2] = CreateGroup()
to my initialization trigger, but the bug is still here....btw I've read something about dynamic indexing system..but why is that so good?

I think i got it. You wrote here bad Unit Group... if I use
  • Custom script: set udg_NSCheckGroup[0] = CreateGroup()
  • Custom script: set udg_NSCheckGroup[1] = CreateGroup()
  • Custom script: set udg_NSCheckGroup[2] = CreateGroup()
  • Custom script: set udg_NSCheckGroup[3] = CreateGroup()
  • Custom script: set udg_NSCheckGroup[4] = CreateGroup()
  • Custom script: set udg_NSCheckGroup[5] = CreateGroup()
it works five times and then don't...I understand why..the unit group isn't created...but here I probably need the index system to reduce index number, right?
 
Last edited by a moderator:
Status
Not open for further replies.
Top