• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

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.
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
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.
 
Level 3
Joined
Sep 11, 2004
Messages
63
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?
 
Level 8
Joined
Aug 6, 2008
Messages
451
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.
 
Level 3
Joined
Sep 11, 2004
Messages
63
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.
 
Level 8
Joined
Aug 6, 2008
Messages
451
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.
 
Level 3
Joined
Sep 11, 2004
Messages
63
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.
Top