• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Question about Leaks (Unit Group)

Status
Not open for further replies.
Level 31
Joined
Apr 17, 2009
Messages
3,571
Am I using the custom script right, so my trigger doesn't leak?

  • Campfire Burn Off
    • Events
      • Time - Every 10.00 seconds of game time
    • Conditions
    • Actions
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units of type Campfire (Fire)) and do (Actions)
        • Loop - Actions
          • Unit - Set mana of (Picked unit) to ((Mana of (Picked unit)) - 10.00)
 
Level 11
Joined
Jan 25, 2009
Messages
572
Yeah it works ^^. You can also, if you want, add the unit group into a variable and store it vefore using it and the after you can destroy it, but since that is just a safe way to make spells, you can use this easy way and pretty safe also (you're saving memory cuz the variable don't need to be created and you can have shorter trigger), so use this way you're using it now ^^.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
Actually that isn't true. This is the function he is referencing in his trigger:

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

As you can see, bj_wantDestroyGroup is not factored in here, so the group will need to be destroyed manually via custom script. This function also leaks a variable reference of type group, it would seem (nothing you can do about that).

JASS:
native DestroyGroup takes group whichGroup returns nothing
 
Level 9
Joined
Jun 25, 2009
Messages
427
Maybe try doing something like this

  • Events:
    • Time - Every 10.00 Seconds of the game time
  • Conditions:
  • Actions:
    • Set Campfire_Units=Unit in Campfire <gen>
    • Unit Group - Pick every units in (Campfire_Units) and do (actions):
      • Unit - Set Mana of (Picked Unit) to (Mana of Picked Unit) - 10
    • Custom Script: call DestroyGroup(udg_Campfire_Units)
 
Level 13
Joined
Mar 16, 2008
Messages
941
Actually that isn't true. This is the function he is referencing in his trigger:

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

As you can see, bj_wantDestroyGroup is not factored in here, so the group will need to be destroyed manually via custom script. This function also leaks a variable reference of type group, it would seem (nothing you can do about that).

JASS:
native DestroyGroup takes group whichGroup returns nothing

Wrong. You shouldn't look for group creation but the ForGroupBJ! It doesn't matter how the enum function works.
JASS:
function ForGroupBJ takes group whichGroup, code callback 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

    call ForGroup(whichGroup, callback)

    // If the user wants the group destroyed, do so now.
    if (wantDestroy) then
        call DestroyGroup(whichGroup)
    endif
endfunction
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
Awww!!! I was like "there's no way its in the ForGroupBJ - mind you I think that was posted at like 4AM last night so I was probably dead-tired.
 
Last edited:
Status
Not open for further replies.
Top