What the heck? Why does this not work correctly?

jwallstone

New Member
Reaction score
33
GroupEnumUnitsInRectCounted is supposed to add units to a group up to a certain number (hence Counted), right? Then why the heck is it creating a group with more than the specified number of units?

I display the number of units in the group and the maximum count entered into the argument list right after calling the function, and the group is larger than it should be.

Is there anything that could allow this to add more units than allowed?
 

jwallstone

New Member
Reaction score
33
Here a simple test, at map initialization:

JASS:
local group group1 = CreateGroup()
call GroupEnumUnitsInRectCounted(group1, GetPlayableMapRect(), null, 12)
call BJDebugMsg("Groupsize: " + I2S(CountUnitsInGroup(group1)))


Result? "Groupsize: 764".

Thank You Blizzard, for a crappy function that absolutely does not work the way it's supposed to. I mean, you'd think the lack of anything resembling decent garbage collection or proper reference counting for local variables going out of scope would be enough, but I guess not.

Sorry, had to vent.
 

scorpion182

New Member
Reaction score
5
try this
JASS:

function filter takes nothing returns boolean
    return (GetWidgetLife(GetFilterUnit()) > 0.405)
endfunction 

function Actions takes nothing returns nothing
    local group g = CreateGroup()
    local boolexpr b= Condition(function filter)
    local unit u
    local integer count=0
    
    call GroupEnumUnitsInRange(g,0,0,99999.0,b)
    
    loop
        set u=FirstOfGroup(g)
    exitwhen u==null
        call GroupRemoveUnit(g,u)
        set count=count+1
    endloop
    
    call DisplayTimedTextToPlayer(Player(0),0,0,60,"Groupsize: " + I2S(count))
    
    call DestroyGroup(g)
    call DestroyBoolExpr(b)
    
    set u=null
    set b=null
    set g=null
endfunction
 

jwallstone

New Member
Reaction score
33
What is the purpose of your function? It looks like you're just counting all units with life greater than 0.405 (Why that number?).

I think you may have misunderstood my point. The function GroupEnumUnitsInRectCounted is supposed to return a group with a size up to the maximum size specified, which in my example was 12 (the last argument). It clearly does not do that, as it returned a group of all units on the map.
 

roXplosive

New Member
Reaction score
15
Make a global/local ar as you need . Make a filter that icreases the variable and hae fun :

JASS:

scope WTFPWN
globals
    private integer maxunits
    private integer curunits
endglobals

private function Less takes nothing returns nothing
 set curunits=curunits+1
 return curunits<=maxunits
endfunction

function GroupEnumUnitsInRectCounted takes group g , rect r , integer i returns nothing
    set maxunits=i
    set curunits=0
    call GroupEnumUnitsInRect(g,r,Filter(function Less))
endfunction

endscope


I think this would do the trick .
 

jwallstone

New Member
Reaction score
33
Yeah, that'd do the trick. I pretty much also come to the conclusion that was the way to go, but thanks. I was just annoyed that such a simple native function doesn't even perform the way it's supposed to.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top