• 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] A question about "for Every Unit in Group Matching Condition, do..."

Status
Not open for further replies.
Level 4
Joined
Aug 12, 2004
Messages
76
For the
For Every Unit in Group matching Conditions, do....

How does that work? I am pretty new to JASS but I get the basics.
When I convert it from GUI to JASS,

It has like 3 actions

1 function for condition

1 for action

and another for action with it containing for each unit, with condition, given condition, and action given action.

Or is there a simpler way to do it?
I thought about storing group into a variable then setting if, then, else condition for each unit in group, but I found out that it basically leads back to the beginning...
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
[jass=Ways to enum]//Conventional way - Side Effects: No locals from parent function
function Blah_Child takes nothing returns nothing
local unit u = GetEnumUnit()
//do stuff
endfunction

function Blah takes nothing returns nothing
//enum someGroup
//ForGroup just loops through every unit in a group, and for each one executes the specified child function with GetEnumUnit() as the current unit
call ForGroup(someGroup,function Blah_Child)
endfunction

//Alternative way - Side Effects: Clears group
function Blah takes nothing returns nothing
local unit u
//enum for someGroup
//begin a loop
loop
//u becomes the first unit in someGroup
set u = FirstOfGroup(someGroup)
//if u is null, the group is empty; abort
exitwhen u == null
//remove u from the group so that the next unit is moved to when the next execution comes
call GroupRemoveUnit(someGroup,u)
//do stuff
endloop
endfunction[/code]

About the 'Condition', that's a boolexpr within GroupEnumUnitsInBlah.

A boolexpr is made like this:

JASS:
Filter(function someFuncThatReturnsABoolean) //returns filterfunc, a child type of boolexpr, used in groups, etc
Condition(function someFuncThatReturnsABoolean) //returns conditionfunc, a child type of boolexpr, used in trigger conditions
While the two are intended for specific purposes, they may be used interchangeably to my knowledge.

Inside the filter, there is a GetFilterUnit() which is the unit being checked.
 
Status
Not open for further replies.
Top