• Check out the results of the Techtree Contest #19!
  • 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.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

Questions about unit groups

Status
Not open for further replies.
Level 3
Joined
Sep 11, 2004
Messages
63
I feel a bit stupid and ignorant after retiring from mapping for so long, so more noobish questions from me =)

Q1:

IsUnitGroupDeadBJ from 1.24 blizzard.j:
Code:
    // Memory cleanup vars
    boolean            bj_wantDestroyGroup         = false



function IsUnitGroupDeadBJEnum takes nothing returns nothing
    if not IsUnitDeadBJ(GetEnumUnit()) then
        set bj_isUnitGroupDeadResult = false
    endif
endfunction

//===========================================================================
// Returns true if every unit of the group is dead.
//
function IsUnitGroupDeadBJ takes group g returns boolean
    // 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_isUnitGroupDeadResult = true
    call ForGroup(g, function IsUnitGroupDeadBJEnum)

    // If the user wants the group destroyed, do so now.
    if (wantDestroy) then
        call DestroyGroup(g)
    endif
    return bj_isUnitGroupDeadResult
endfunction

As you can see IsUnitGroupDeadBJ will leak if bj_wantDestroyGroup is set to false, which is the default value defined in blizzard.j. So do I need to set bj_wantDestroyGroup to true manually in map initialization trigger?

Q2:

Does DestroyGroup a null unitgroup have any side effect?

I asked because the variable I am passing to DestroyGroup might be null

Thanks.
 
You have to set it to true manually everytime you pick a unit group that isnt set in a variable, because as you can see, it is set to false again immediately!

I do not recommend to pass a null group to it, for i do not know what will happen. Check if it is null first before passing it.
 
Thanks one more questions though

Some function like this one:
Code:
function foo takes group g1 returns nothing
  local group g2 = CreateGroup()
  call GroupAddGroup(g1, g2)
  //do something on g2
  call DestroyGroup(g2)
endfunction

Do i need to do

Code:
set g1 = null
set g2 = null

at the end of such function?
 
You should get GroupUtils from wc3c.net and recycle your groups, instead of destroying them. Thats what you should do.

Nulling groups is useless, unless you destroy them, which is something you dont have to do, because recycling groups is better option.

Calling GroupEnum on any other group than some global EnumGroup is also stupid, because GroupEnum:

1) is instant, so you dont need more than one group for calling your GeoupEnums,

2) leaks with temporary groups.
 
oh I see the problem now, so GroupAddGroup leaks number of units in source group unit variable from GetEnumUnit()?

I checked grouputils, but it's in vJass, and I am still not motivated to use custom jass compiler or features.
 
Ok, but let me tell you that Jassing without vJass is pain in the ass. ( Well, at least after you learn vjass )

So I highly recommend you to think again.
 
Yea I know many people swear by vJass, but what I am messing around with is a multi-thousands line script in plain old Jass, I would consider using vJass if I were making something from scratch, but for a monolithic thing like that... meh.
 
Status
Not open for further replies.
Back
Top