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

[JASS] JASS of "Pick Every Unit in Group Matching..."

Status
Not open for further replies.
Level 4
Joined
Nov 24, 2007
Messages
55
I was wondering what the best "JASS" solution to doing something akin to this:

Iterate through a group of units that
- match a condition I can specify in a function (preferably a function that could take a unit parameter...GetFilterUnit() is okay...but i'd prefer and assume there is a better way)

- further, call a function on that unit (again, preferably one I could pass things in as parameters and not use GetEnumUnit()...preferably)

Thanks!
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
I think boolexpr (GetFilterUnit()) is the best way to go:

JASS:
function GroupFilter takes nothing returns boolean
    return GetWidgetLife(GetFilterUnit()) > 0
endfunction

function Func takes nothing returns nothing
    local group g = CreateGroup()
    local unit c = GetTriggerUnit()
    local real x = GetUnitX(c)
    local real y = GetUnitY(c)
    call GroupEnumUnitsInRange(g, 500, x, y, Filter(function GroupFilter))
    // ...
    // ...
endfunction

The only other way I can think of is this (but it's inefficient):

JASS:
function GroupFilter takes unit u returns boolean
    return GetWidgetLife(u) > 0
endfunction

function Func takes nothing returns nothing
    local group g = CreateGroup()
    local group g2 = CreateGroup()
    local unit c = GetTriggerUnit()
    local unit u
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    call GroupEnumUnitsInRange(g, 500, x, y, null)
    call GroupEnumUnitsInRange(g2, 500, x, y, null)
    loop
        set u = FirstOfGroup(g2)
        exitwhen u == null
        call GroupRemoveUnit(g2, u)
        if GroupFilter(u) then
            call GroupRemoveUnit(g, u)
        endif
    endloop
    // ...
    // ...
endfunction

As you can see.....
 
Level 4
Joined
Nov 24, 2007
Messages
55
Does "GroupEnumUnitsInRange" just make the group contain those units, then I would need to iterate through the group myself (by making a unit var equal to the first of group, then removing it etc.?)

Or did you leave out the code where I can call a function on these units?
 
Status
Not open for further replies.
Top