Unit Groups in jass? (probably very basic question)

Sartan

New Member
Reaction score
23
how are you using unit groups in JASS compare to how you use them in GUI?

is it owrking kind of the same?
else how does it work?

for an example, would this be correct usage of unit groups in jass? (yeah i'm new on this, dont expect to much of me)

JASS:
function Group_action_test takes nothing returns nothing
    //am i supost to do my action here?
    //should i refear to picked unit in jass to for my unit in the unit group?
endfunction

function test_action_trigger takes nothing returns nothing
    call ForGroupBJ( udg_test_group_u, function Group_action_test )
endfunction


edit: maybe this should have been in jass help
 

jackall

You can change this now in User CP.
Reaction score
37
and example of using unit groups in JASS would be:

JASS:
function groupFilter takes nothing returns boolean
  return (IsUnitType(GetEnumUnit(),UNIT_TYPE_SUMMONED) != true)
endfunction

function FGHeal takes nothing returns nothing
    call SetUnitLifeBJ(GetEnumUnit(),(GetUnitStateSwap(UNIT_STATE_LIFE,GetEnumUnit())+15.00))
endfunction

function trigActions takes nothing returns nothing
  local group toHealGroup = GetUnitsInRectMatching(GetPlayableMapRect(),Condition(function groupFilter))
    call ForGroupBJ(toHealGroup,function FGHeal)
    call DestroyGroup(toHealGroup)
endfunction

notice that i pick units in playable map and filter them so it only heals non-summoned units(the GetUnitsInRectMatching and groupFilter)
 

Executor

I see you
Reaction score
57
Well in GUI you basically create everytime a new group by calling "set GroupVar = Units matching something"

In JASS it's best to reuse one Group for everything.

Trigger:
  • Group Test
    • Ereignisse
      • Spieler - Spieler 1 (Rot) types a chat message containing killall as Exakte Ãœbereinstimmung
    • Bedingungen
    • Aktionen
      • Set someGroup = (Units in (Playable map area) matching (True Gleich (==) True))
      • Einheitengruppe - Pick every unit in someGroup and do (Actions)
        • Schleifen - Aktionen
          • Einheit - Kill (Picked unit)


JASS:
function Trig_Group_Test_Func001002002 takes nothing returns boolean
    return ( true == true )
endfunction

function Trig_Group_Test_Func002A takes nothing returns nothing
    call KillUnit( GetEnumUnit() )
endfunction

function Trig_Group_Test_Actions takes nothing returns nothing
    set udg_someGroup = GetUnitsInRectMatching(GetPlayableMapRect(), Condition(function Trig_Group_Test_Func001002002))
    call ForGroupBJ( udg_someGroup, function Trig_Group_Test_Func002A )
endfunction

//===========================================================================
function InitTrig_Group_Test takes nothing returns nothing
    set gg_trg_Group_Test = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Group_Test, Player(0), "killall", true )
    call TriggerAddAction( gg_trg_Group_Test, function Trig_Group_Test_Actions )
endfunction


becomes this in vJass:

JASS:
scope KillAll initializer INIT

globals
    private group Group = CreateGroup()
endglobals

private function KillEx takes nothing returns boolean
    call KillUnit( GetFilterUnit() )
    return false
endfunction


private function KillAllEx takes nothing returns boolean
    call GroupClear(Group)
    call GroupEnumUnitsInRect(Group, GetPlayableMapRect(), Condition( function KillEx ))
    return false
endfunction

private function INIT takes nothing returns nothing
    local trigger OnKillAllMessage = CreateTrigger()
    call TriggerRegisterPlayerChatEvent( OnKillAllMessage, Player(0), "killall", true )
    call TriggerAddCondition( OnKillAllMessage, Condition(function KillAllEx) )
endfunction
endscope
 

Komaqtion

You can change this now in User CP.
Reaction score
469
First, yeah probaly JASS Help would be better ;)

Second, well, yeah that's how you use it, and in that "Group_action_test" function is where you do the actions but you first need to set the unit-group to something, by using of the the GroupEnumUnits natives...
 

Sartan

New Member
Reaction score
23
and example of using unit groups in JASS would be:

JASS:
function groupFilter takes nothing returns boolean
  return (IsUnitType(GetEnumUnit(),UNIT_TYPE_SUMMONED) != true)
endfunction

function FGHeal takes nothing returns nothing
    call SetUnitLifeBJ(GetEnumUnit(),(GetUnitStateSwap(UNIT_STATE_LIFE,GetEnumUnit())+15.00))
endfunction

function trigActions takes nothing returns nothing
  local group toHealGroup = GetUnitsInRectMatching(GetPlayableMapRect(),Condition(function groupFilter))
    call ForGroupBJ(toHealGroup,function FGHeal)
    call DestroyGroup(toHealGroup)
endfunction

notice that i pick units in playable map and filter them so it only heals non-summoned units(the GetUnitsInRectMatching and groupFilter)

JASS:
function Group_1Condition takes nothing returns boolean
    return ( IsUnitAlly(GetFilterUnit(), GetOwningPlayer(GetTriggerUnit())) == false )
endfunction

function Action_for_Group_1 takes nothing returns nothing
    call KillUnit( GetEnumUnit() )
endfunction

function trigActions takes nothing returns nothing
  local group toHealGroup = GetUnitsInRangeOfLocMatching(250, caster_point, Condition(function Group_1Condition))
    call ForGroupBJ(toHealGroup,function FGHeal)
    call DestroyGroup(toHealGroup)
endfunction


soo... would this work? or did i get it wrong?

Well in GUI you basically create everytime a new group by calling "set GroupVar = Units matching something"

In JASS it's best to reuse one Group for everything.

Trigger:
  • Group Test
    • Ereignisse
      • Spieler - Spieler 1 (Rot) types a chat message containing killall as Exakte Ãœbereinstimmung
    • Bedingungen
    • Aktionen
      • Set someGroup = (Units in (Playable map area) matching (True Gleich (==) True))
      • Einheitengruppe - Pick every unit in someGroup and do (Actions)
        • Schleifen - Aktionen
          • Einheit - Kill (Picked unit)


JASS:
function Trig_Group_Test_Func001002002 takes nothing returns boolean
    return ( true == true )
endfunction

function Trig_Group_Test_Func002A takes nothing returns nothing
    call KillUnit( GetEnumUnit() )
endfunction

function Trig_Group_Test_Actions takes nothing returns nothing
    set udg_someGroup = GetUnitsInRectMatching(GetPlayableMapRect(), Condition(function Trig_Group_Test_Func001002002))
    call ForGroupBJ( udg_someGroup, function Trig_Group_Test_Func002A )
endfunction

//===========================================================================
function InitTrig_Group_Test takes nothing returns nothing
    set gg_trg_Group_Test = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Group_Test, Player(0), "killall", true )
    call TriggerAddAction( gg_trg_Group_Test, function Trig_Group_Test_Actions )
endfunction


becomes this in vJass:

JASS:
scope KillAll initializer INIT

globals
    private group Group = CreateGroup()
endglobals

private function KillEx takes nothing returns boolean
    call KillUnit( GetFilterUnit() )
    return false
endfunction


private function KillAllEx takes nothing returns boolean
    call GroupClear(Group)
    call GroupEnumUnitsInRect(Group, GetPlayableMapRect(), Condition( function KillEx ))
    return false
endfunction

private function INIT takes nothing returns nothing
    local trigger OnKillAllMessage = CreateTrigger()
    call TriggerRegisterPlayerChatEvent( OnKillAllMessage, Player(0), "killall", true )
    call TriggerAddCondition( OnKillAllMessage, Condition(function KillAllEx) )
endfunction
endscope

ddint quit get the vjass thing, whats the diffrent between the second trigger (first jass trigger you posted) and thethird trigger (second jass trigger) effectivnes?

First, yeah probaly JASS Help would be better ;)

Second, well, yeah that's how you use it, and in that "Group_action_test" function is where you do the actions but you first need to set the unit-group to something, by using of the the GroupEnumUnits natives...

could you givem e an example for a GroupEnumUnits natives? didnt quit get that too :p
 

jackall

You can change this now in User CP.
Reaction score
37
JASS:
function ToKillGroupCondition takes nothing returns boolean
    return ( IsUnitAlly(GetFilterUnit(), GetOwningPlayer(GetTriggerUnit())) == false )
endfunction

function ActionforGroup1 takes nothing returns nothing
    call KillUnit( GetEnumUnit() )
endfunction

function trigActions takes nothing returns nothing
  local location casterPoint = GetUnitLoc(GetTriggerunit())
  local group toKillGroup = GetUnitsInRangeOfLocMatching(250,casterPoint,Condition(function ToKillGroupCondition))
    call ForGroupBJ(toHealGroup,function killEnemy)
    call DestroyGroup(toKillGroup)
    call RemoveLocation(casterPoint)
endfunction

should do the trick
 

Executor

I see you
Reaction score
57
JASS:
scope KillAll initializer INIT

globals
    private group Group = CreateGroup()
endglobals

private function KillEx takes nothing returns boolean
    call KillUnit( GetFilterUnit() )
    return false
endfunction


private function KillAllEx takes nothing returns boolean
    call GroupClear(Group)
    call GroupEnumUnitsInRect(Group, GetPlayableMapRect(), Condition( function KillEx ))
    return false
endfunction

private function INIT takes nothing returns nothing
    local trigger OnKillAllMessage = CreateTrigger()
    call TriggerRegisterPlayerChatEvent( OnKillAllMessage, Player(0), "killall", true )
    call TriggerAddCondition( OnKillAllMessage, Condition(function KillAllEx) )
endfunction
endscope


First of all ignore the scope thing and just assume that the "INIT" function is called on map initialization.

The first difference you could see is that I'm not adding a Action to the trigger, but adding a Condition. That's just because Conditions are called faster than Actions and in Conditions you can use all the return values (GetTriggerUnit..) you could use in an Action function. Important for a condition is that it returns boolean.

The second point is that I'm not adding units to the group. I do the actions in the filter condition.. before they are added to the group. Here again conditions are faster and the simple difference is that you have to use GetFilterUnit instead of GetPickedUnit. And because you never add units to the group you can do everything with only one global group (except of storing units..).
 

Sartan

New Member
Reaction score
23
jackall ty it owrkeed... however...

JASS:
scope KillAll initializer INIT

globals
    private group Group = CreateGroup()
endglobals

private function KillEx takes nothing returns boolean
    call KillUnit( GetFilterUnit() )
    return false
endfunction


private function KillAllEx takes nothing returns boolean
    call GroupClear(Group)
    call GroupEnumUnitsInRect(Group, GetPlayableMapRect(), Condition( function KillEx ))
    return false
endfunction

private function INIT takes nothing returns nothing
    local trigger OnKillAllMessage = CreateTrigger()
    call TriggerRegisterPlayerChatEvent( OnKillAllMessage, Player(0), "killall", true )
    call TriggerAddCondition( OnKillAllMessage, Condition(function KillAllEx) )
endfunction
endscope


First of all ignore the scope thing and just assume that the "INIT" function is called on map initialization.

The first difference you could see is that I'm not adding a Action to the trigger, but adding a Condition. That's just because Conditions are called faster than Actions and in Conditions you can use all the return values (GetTriggerUnit..) you could use in an Action function. Important for a condition is that it returns boolean.

The second point is that I'm not adding units to the group. I do the actions in the filter condition.. before they are added to the group. Here again conditions are faster and the simple difference is that you have to use GetFilterUnit instead of GetPickedUnit. And because you never add units to the group you can do everything with only one global group (except of storing units..).

JASS:
private function INIT takes nothing returns nothing
    local trigger OnKillAllMessage = CreateTrigger()
    call TriggerRegisterPlayerChatEvent( OnKillAllMessage, Player(0), "killall", true )
    call TriggerAddCondition( OnKillAllMessage, Condition(function KillAllEx) )
endfunction


this made me fell like someone did a side kick on me :p
How does the trigger run without the actions? :O are the last part, KillEx runnig KillAllEx added units and are working as the "main action" action?

JASS:
    call GroupEnumUnitsInRect(Group, GetPlayableMapRect(), Condition( function KillEx ))

and the scope... does the name you puted on it actually matter? or could i for an example name it MyfirstScope?

Edit: aww oh snap, as more i'm wrighting / edit it makes lesser sence^^

lets say like this then:

JASS:
call TriggerAddCondition( OnKillAllMessage, Condition(function KillAllEx) )


could you say that that replace this one?

JASS:
call TriggerAddAction( gg_trg_Group_Test, function Trig_Group_Test_Actions )
 

Rushhour

New Member
Reaction score
46
You can give it whatever name you want. But look it up at JassHelper manual, since there are restrictions to symbols, the first letter mustn't be a number and the name has to be unique.

For your question concerning the funciton "INIT": it is only called once, by the scope itself: [IJASS] initializer INIT [/IJASS]

Actions or conditions are doing the same stuff, executing code.^^ You can use all your stuff you did in "actions" in "conditions" by simply adding return boolean and a return false at the end. If you have a condition for your trigger you can still check with a
JASS:
 function whatever takes nothing returns boolean
if yourcondition then 
//your code
endif
return false
endfunction

I'm not sure if there really is a speed advantage for normal triggers, but it is great for dynamical triggers (that are created and destroyed during the game) since they don't leak actions.
Edit: I see, he already said most of the stuff I told you.. but one thing: you can't use waits (TriggerSleep) in conditions. But as everyone said.. don't use it anyway, it's inaccurate and so on :rolleyes:
 

Sartan

New Member
Reaction score
23
You can give it whatever name you want. But look it up at JassHelper manual, since there are restrictions to symbols, the first letter mustn't be a number and the name has to be unique.

For your question concerning the funciton "INIT": it is only called once, by the scope itself: [IJASS] initializer INIT [/IJASS]

Actions or conditions are doing the same stuff, executing code.^^ You can use all your stuff you did in "actions" in "conditions" by simply adding return boolean and a return false at the end. If you have a condition for your trigger you can still check with a
JASS:
 function whatever takes nothing returns boolean
if yourcondition then 
//your code
endif
return false
endfunction

I'm not sure if there really is a speed advantage for normal triggers, but it is great for dynamical triggers (that are created and destroyed during the game) since they don't leak actions.
Edit: I see, he already said most of the stuff I told you.. but one thing: you can't use waits (TriggerSleep) in conditions. But as everyone said.. don't use it anyway, it's inaccurate and so on :rolleyes:

hmmm then what if i wanted all unit to "slide" forward every second for 5 seconds after my trigger run? is there any alternativ function for a loop + a wait in it to make a unit slide? (as a perodic timer in gui) that i could use inside a condition?
 

ertaboy356b

Old School Gamer
Reaction score
86
The best part in using jass is that you can exploit alot of functions..

This is for looping groups
JASS:
function GroupAction takes nothing returns nothing
   call DisplayTextToPlayer(GetTriggerPlayer(),0,0,GetUnitName(GetEnumUnit()))
endfunction

function Actions takes nothing returns nothing
   call ForGroup(MyUnitGroup,function GroupActions)
endfunction


The above function will display the name of every unit in a group

JASS:
function Kill takes nothing returns boolean
   call KillUnit(GetFilterUnit())
   return false
endfunction

function Actions takes nothing returns nothing
   call GroupEnumUnitsInRect(Group, GetPlayableMapRect(), Condition( function Kill ))
endfunction


The above function will kill every unit in the map..
The above function is what I call an exploit :) since you do the actions inside the condition... You can even filter it by using If statements..
 

Sartan

New Member
Reaction score
23
The best part in using jass is that you can exploit alot of functions..

This is for looping groups
JASS:



function GroupAction takes nothing returns nothing
   call DisplayTextToPlayer(GetTriggerPlayer(),0,0,GetUnitName(GetEnumUnit()))
endfunction

function Actions takes nothing returns nothing
   call ForGroup(MyUnitGroup,function GroupActions)
endfunction


The above function will display the name of every unit in a group

JASS:


function Kill takes nothing returns boolean
   call KillUnit(GetFilterUnit())
   return false
endfunction

function Actions takes nothing returns nothing
   call GroupEnumUnitsInRect(Group, GetPlayableMapRect(), Condition( function Kill ))
endfunction


The above function will kill every unit in the map..
The above function is what I call an exploit :) since you do the actions inside the condition... You can even filter it by using If statements..

thats realy looks usefull :eek:
but still have some old as new questions :p
This is for looping groups
JASS:



function GroupAction takes nothing returns nothing
   call DisplayTextToPlayer(GetTriggerPlayer(),0,0,GetUnitName(GetEnumUnit()))
endfunction

function Actions takes nothing returns nothing
   call ForGroup(MyUnitGroup,function GroupActions)
endfunction

does this resemble
Code:
Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
    Loop - Actions
action in GUI?

if not, or if:
since i cant loop conditions with triggersleep in it, how do i make a "periodic trigger that moves all unit in unitgroup_A forward with 100"wc3 meters" every 1 second?

sorry if i'm just plain dumb, but dont rly seem to understand everything about using groups in jass.
 

jackall

You can change this now in User CP.
Reaction score
37
you could make an initially disabled trigger that runs every second and pick every unit in that group and moves it 100 units farther away
JASS:
function FiLtEr takes nothing returns boolean
  return (IsUnitType(GetEnumUnit(),UNIT_TYPE_HERO) == true)
endfunction

function moveUnit takes nothing returns nothing
  local location unitLoc = GetUnitLoc(GetEnumUnit())
    call SetUnitX(GetEnumUnit(),GetLocationX(unitLoc))
    call SetUnitY(GetEnumUnit(),GetLocationY(unitLoc))
    call RemoveLocation(unitLoc)
endfunction

function moveGroup takes nothing returns nothing
  local location point1 = GetRandomLocInRect(GetPlayableMapRect())
  local group toMove = GetUnitsInRangeOfLocMatching(2500,point1,Condition(function FiLtEr))
    call ForGroup(toMove,function moveUnit)
    call RemoveLocation(point1)
    call DestroyGroup(toMove)
endfunction

function InitTrig_kjekef takes nothing returns nothing
    set gg_trg_kjekef = CreateTrigger()
    call TriggerRegisterTimerEventPeriodic(gg_trg_kjekef,1.00)
    call TriggerAddAction(gg_trg_kjekef,function moveAction)
endfunction

this will move all hero units within 2500 range of point1
notice that every second the location point1 changes location
 

ertaboy356b

Old School Gamer
Reaction score
86
thats realy looks usefull :eek:
but still have some old as new questions :p


does this resemble
Code:
Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
    Loop - Actions
action in GUI?

if not, or if:
since i cant loop conditions with triggersleep in it, how do i make a "periodic trigger that moves all unit in unitgroup_A forward with 100"wc3 meters" every 1 second?

sorry if i'm just plain dumb, but dont rly seem to understand everything about using groups in jass.

1. Yes it resembles that in GUI

2. you can use ForGroup in a loop..

JASS:

function GroupAction takes nothing returns nothing
   // Your Actions
endfunction

function Action takes nothing returns nothing
   loop
     exitwhen <Your Conditions>
     call ForGroup(Group,function GroupAction)
     call TriggerSleepAction(1)
  endloop
endfunction
 

GetTriggerUnit-

DogEntrepreneur
Reaction score
129
Use a group-loop imo.

Instead of:
JASS:

function ingroup takes nothing returns nothing
    call DoSomething(GetEnumUnit())
endfunction

function func takes nothing returns nothing
    local group g=CreateGroup()
    call ForGroup(g,function ingroup)
    call DestroyGroup(g)
    set g=null
endfunction


do:

JASS:

function func takes nothing returns nothing
    local group g=CreateGroup()
    local unit u=null
    loop
         set u=FirstOfGroup(g)
         exitwhen u==null
         call DoSomething(u)
         call GroupRemoveUnit(g,u)
    endloop
    call DestroyGroup(g)
    set g=null
endfunction
 

Executor

I see you
Reaction score
57
Use a group-loop imo.

Instead of:
JASS:

function ingroup takes nothing returns nothing
    call DoSomething(GetEnumUnit())
endfunction

function func takes nothing returns nothing
    local group g=CreateGroup()
    call ForGroup(g,function ingroup)
    call DestroyGroup(g)
    set g=null
endfunction


do:

JASS:

function func takes nothing returns nothing
    local group g=CreateGroup()
    local unit u=null
    loop
         set u=FirstOfGroup(g)
         exitwhen u==null
         call DoSomething(u)
         call GroupRemoveUnit(g,u)
    endloop
    call DestroyGroup(g)
    set g=null
endfunction

but the second one is better because you can better use local vars for all units and not for one specificly.
 

Sartan

New Member
Reaction score
23
but the second one is better because you can better use local vars for all units and not for one specificly.

well cant understand the basic construction of the second one,

JASS:
function func takes nothing returns nothing
    local group g=CreateGroup()
    local unit u=null
    loop
         set u=FirstOfGroup(g)
         exitwhen u==null
         call DoSomething(u)
         call GroupRemoveUnit(g,u)
    endloop
    call DestroyGroup(g)
    set g=null
endfunction

for an example
JASS:
         set u=FirstOfGroup(g)

does this set the first unit that will be picked in my group as unit u?

JASS:
         call DoSomething(u)

is it here i should do my things as move unit u to position x?

JASS:
         call GroupRemoveUnit(g,u)

is this when unit u becomes null? and it stops looping? or is it when unitgroup g runs out of units it set itself to null?
 
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