• 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.
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!
  • ✅ The POLL for Hive's Texturing Contest #34 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!
  • ✅ The POLL for Hive's Techtree Contest #20 is OPEN! Vote for the TOP 3 FACTIONS! 🔗Click here to cast your vote!

Does this leaks?

Status
Not open for further replies.
Level 20
Joined
Jul 14, 2011
Messages
3,213
  • Untitled Trigger 001
    • Events
    • Conditions
    • Actions
      • Custom script: set bj_wantDestroyGroup = true
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in (Units in WoodsEasy <gen> matching (((Unit-type of (Matching unit)) Equal to Bear (Black Spider)) or ((Unit-type of (Matching unit)) Equal to Wolf)))) Greater than 2
          • Or - Any (Conditions) are true
            • Conditions
              • (Unit-type of A) Equal to Bear (Black Spider)
              • (Unit-type of A) Equal to Wolf
        • Then - Actions
          • Unit - Change ownership of A to Neutral Passive and Change color
          • Unit - Replace A with a WoodCreeps[(Random integer number between 1 and 6)] using The new unit's default life and mana
          • Game - Display to (All players) the text: Unit Replaced! <- Debug Msg
        • Else - Actions
This is just a small part of the trigger. My doubt is in these lines:

  • Custom script: set bj_wantDestroyGroup = true
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • (Number of units in (Units in WoodsEasy <gen> matching (((Unit-type of (Matching unit)) Equal to Bear (Black Spider)) or ((Unit-type of (Matching unit)) Equal to Wolf)))) Greater than 2
I've heard that the custom script placed there solves the UnitGroup created for the condition.

What am I doing? It's a wood region which has neutral creeps (which turn hostile when hit) and hostile creeps (which are aggresive), but I just want to have 2 aggresive creeps at the same time (Wolves and Bears), so, if the unit created is a bear/wolf and there's already 2 wolf or bears (or both) in the region, change the unit for a passive one.
 
This causes a leak for example:
  • Actions
    • Custom script: set bj_wantDestroyGroup = true
    • Unit Group - Pick every unit in (Units of type Footman) and do (Actions)
      • Loop - Actions
->
JASS:
function Trig_Untitled_Trigger_042_Actions takes nothing returns nothing
    call ForGroupBJ( GetUnitsOfTypeIdAll('hfoo'), function Trig_Untitled_Trigger_042_Func001A )
endfunction
->
JASS:
function GetUnitsOfTypeIdAll takes integer unitid returns group
    local group   result = CreateGroup()
    local group   g      = CreateGroup()
    local integer index

    set index = 0
    loop
        set bj_groupEnumTypeId = unitid
        call GroupClear(g)
        call GroupEnumUnitsOfPlayer(g, Player(index), filterGetUnitsOfTypeIdAll)
        call GroupAddGroup(g, result)

        set index = index + 1
        exitwhen index == bj_MAX_PLAYER_SLOTS
    endloop
    call DestroyGroup(g)

    return result
endfunction
->
JASS:
function GroupAddGroup takes group sourceGroup, group destGroup returns nothing
    // If the user wants the group destroyed, remember that fact and clear
    // the flag, in case it is used again in the callback.
    local boolean wantDestroy = bj_wantDestroyGroup
    set bj_wantDestroyGroup = false

    set bj_groupAddGroupDest = destGroup
    call ForGroup(sourceGroup, function GroupAddGroupEnum)

    // If the user wants the group destroyed, do so now.
    if (wantDestroy) then
        call DestroyGroup(sourceGroup)
    endif
endfunction
 
What would be the efficient way to "Pick Every unit in (Units of Type)"?

  • Trigger
  • Custom script: call bj_wantDestroyGroup = true
    • Unit Group - Pick every unit in (Units of typeFootman) and do (Actions)
      • Loop - Actions
      • Whatever
  • Custom script: call DestroyGroup(sourceGroup)
?
 
Status
Not open for further replies.
Back
Top