• 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.

Variable Question

Status
Not open for further replies.
Level 6
Joined
Dec 8, 2016
Messages
127
Is these 2 variables basically the same thing? example:

Set UnitVariable = (Random unit from WhateverGroup1)
Set WhateverGroup2 = (Random 1 units from (WhateverGroup1))

If it is same then i assume the unit variable is faster, i don't have to clean group leak.
 
It's actually not directly related, but I still mention it because I've seen people abusing it too much.

People in GUI often like to use it to get their builder/hero from their map like:

  • Unit - Move (Random Unit From (Player 1 Players of Type <Hero>)) to <Region>)
...-- with the argument they have only one hero, so it will work always. But I can just say it's a horrible way of doing, and in case you're using it similary, then none of the mentioned 2 ways is good.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,285
Set UnitVariable = (Random unit from WhateverGroup1)
This does not leak.
Set WhateverGroup2 = (Random 1 units from (WhateverGroup1))
This does leak. Unless the local declared local handle variable reference counter leak on return bug has been fixed with 1.27b (probably needs retesting).
JASS:
function GetRandomSubGroup takes integer count,group sourceGroup returns group
    local group g = CreateGroup()
    set bj_randomSubGroupGroup = g
    set bj_randomSubGroupWant  = count
    set bj_randomSubGroupTotal = CountUnitsInGroup(sourceGroup)
    if (bj_randomSubGroupWant <= 0 or bj_randomSubGroupTotal <= 0) then
        return g
    endif
    set bj_randomSubGroupChance = I2R(bj_randomSubGroupWant) / I2R(bj_randomSubGroupTotal)
    call ForGroup(sourceGroup, function GetRandomSubGroupEnum)
    return g
endfunction
Local declared local group variable g is not null at function return. People have also reported that the results are not truly random due to a logical error with the selection probability.
 
Status
Not open for further replies.
Top