• 🏆 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!

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,202
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