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

Status
Not open for further replies.
Level 9
Joined
Jun 7, 2008
Messages
440
Hey there. I was working on a few things and came across this:
JASS:
function GetUnitsOfPlayerMatching takes player whichPlayer, boolexpr filter returns group
    local group g = CreateGroup()
    call GroupEnumUnitsOfPlayer(g, whichPlayer, filter)
    call DestroyBoolExpr(filter)
    return g
endfunction

Can anyone tell me what "filter" is?
 
Level 4
Joined
Jul 24, 2010
Messages
85
filter is the name of variable that you have created in the function line.

function GetUnitsOfPlayerMatching takes player whichPlayer, boolexpr filter returns group

That's mean this function need 2 variable to run
1. player - name of variable you created = whichPlayer
2. boolexpr - name of variable you created = filter
When you want to run the function, you will need to call this function and give 2 parameter (that's variable type of "player" and "boolexpr").
After running this function, you will get variable "g" which is type of "group"


The name of variable isn't fixed so you may change it to what you want.

Jass Language will work like C,C++. Here the tutorial http://www.cplusplus.com/doc/tutorial/functions/
 
Level 9
Joined
Jun 7, 2008
Messages
440
Im afraid I don't follow. In this instance I would like to get all units from certain players. How would I complete the filter function if all I need is already in the script?
 
Level 9
Joined
Jun 7, 2008
Messages
440
In GUI, you ask for the player, the condition being the one that triggered the event. If the trigger is aready firing, and I call the units of the triggering player;
JASS:
    call GroupEnumUnitsOfPlayer(g, whichPlayer,// filter - Why would I need the filter? All conditions have been met)

Sorry, I cannot seem to wrap my head around this one. Would it be possible to give me an example of the kind of use for this filter?
 
JASS:
function check takes nothing returns boolean
      return GetWidgetLife(GetFilterUnit()) > 100
endfunction

function whatthe takes nothing returns nothing
   call GroupEnumUnitsOfPlayer(g, whichPlayer, Filter(function check))
endfunction

//now this will pick every unit owned by whichplayer that has hit points > 100

//if you dont need any filter/condition you can set that parameter to null
call GroupEnumUnitsOfPlayer(g, whichPlayer, null)
//this will pick every unit owned by the player

//basically the filter function will FILTER which units will be added to the unit group
 
Status
Not open for further replies.
Top