Counting units and leaks

Level 3
Joined
May 28, 2019
Messages
37
Hello friends!

For my techtree trigger I need to count units of type "Goblin Laboratory" on the map.

But I'm afraid it will leak because of "dynamic unit group". Will it?

Thank you in advance for your reply!

My trigger:
  • Units Restrictions
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Player - Limit training of Troll Assassin (normal form) to 1 for (Picked player)
          • Player - Limit training of Death Knight (dark horde) to 1 for (Picked player)
          • Player - Make Troll Berserker (dark horde) Unavailable for training/construction by (Picked player)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in (Units of type Goblin Laboratory)) Equal to 0
            • Then - Actions
              • Player - Make Goblin Zeppelin (dark horde) Unavailable for training/construction by (Picked player)
            • Else - Actions
[/spoiller]
 
Level 9
Joined
Mar 26, 2017
Messages
362
Yes the 'all units of type' creates an unpreventable handle leak in JASS.
Do you know which player owns the Goblin Laboratories?

Then you can put something like this:
  • Number of units in (Units owned by Player x matching type = Goblin Laboratory)
And you have to put the following custom script line right before that:
  • Custom Script: set bj_wantDestroyGroup = true

Otherwise if you use Lua mode, you can keep the code you already had, and just put the custom script line.
 
Level 3
Joined
May 28, 2019
Messages
37
Yes the 'all units of type' creates an unpreventable handle leak in JASS.
Do you know which player owns the Goblin Laboratories?

Then you can put something like this:
  • Number of units in (Units owned by Player x matching type = Goblin Laboratory)
And you have to put the following custom script line right before that:
  • Custom Script: set bj_wantDestroyGroup = true

Otherwise if you use Lua mode, you can keep the code you already had, and just put the custom script line.
Thank you very much! I'm not sure I understood you correctly, so I'll post updated trigger here:
  • Units Restrictions
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Player - Limit training of Troll Assassin (normal form) to 1 for (Picked player)
          • Player - Limit training of Death Knight (dark horde) to 1 for (Picked player)
          • Player - Make Troll Berserker (dark horde) Unavailable for training/construction by (Picked player)
          • Custom script: set bj_wantDestroyGroup = true
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of living Goblin Laboratory units owned by Neutral Passive) Equal to 0
            • Then - Actions
              • Player - Make Goblin Zeppelin (dark horde) Unavailable for training/construction by (Picked player)
            • Else - Actions
 
Level 9
Joined
Mar 26, 2017
Messages
362
The following functions have to be avoiding:
-Units of type
-Number of living units

Use this:
  • (Number of units in (Units owned by Neutral Passive matching ((((Matching unit) is alive) Equal to True) and ((Unit-type of (Matching unit)) Equal to Goblin Laboratory)).)) Equal to 0
Or if the 'alive' part does not matter (depending on whether decaying buildings should count or not), a simpler function:
  • (Number of units in (Units owned by Neutral Passive of type Goblin Laboratory)) Equal to 0
 
Last edited:
Level 32
Joined
Aug 10, 2018
Messages
3,397
The following functions have to be avoiding:
-Units of type
-Number of living units

Use this:
  • (Number of units in (Units owned by Neutral Passive matching ((((Matching unit) is alive) Equal to True) and ((Unit-type of (Matching unit)) Equal to Goblin Laboratory)).)) Equal to 0
Or if the 'alive' part does not matter (depending on whether decaying buildings should count or not), a simpler function:
  • (Number of units in (Units owned by Neutral Passive of type Goblin Laboratory)) Equal to 0
Doesn't your second suggestion still leak? I think you meant to suggest:
  • (Number of units in (Units owned by Neutral Passive matching (((Unit-type of (Matching unit)) Equal to Goblin Laboratory)).)) Equal to 0
 
Top