# [Solved] How to Group unit without uses boolenexplr

Discussion in 'Triggers & Scripts' started by ALTELMA, Apr 20, 2012.

1. ### Starquizer

Joined:
Mar 3, 2006
Messages:
1,526
Resources:
6
Maps:
1
Spells:
2
Tutorials:
3
Resources:
6
GroupEnumUnitsInRange(g,x,y,r,filter)

g: group, it is the group that the picked unit will be added to.
x: real, the X coordinate of the centre point of the picking circle.
y: real, the Y coordinate of the centre point of the picking circle.
r: real, is the radius the circle that the function will pick units from.
filter: boolexpr, if you want the unit to has special condition, but we regularly avoid this to prevent creation of another thread so we use FirstOfGroup and match the unit one by one.

2. ### Troll-Brain

Joined:
Apr 27, 2008
Messages:
2,372
Resources:
1
JASS:
1
Resources:
1

Code (vJASS):
call GroupEnumUnitsInRange(g, 0, 0, 1000000000, null)

loop
set u = FirstOfGroup(g)
exitwhen u == null
if(GetUnitTypeId(u) == 'hf00')then
set unitCount =unitCount + 1
call BJDebugMsg(I2S(unitCount))
endif
call GroupRemoveUnit(g,u)
endloop

->

Code (vJASS):
call GroupEnumUnitsInRange(g, 0, 0, 1000000000, null)

for u in g

if(GetUnitTypeId(u) == 'hf00')then
set unitCount =unitCount + 1
call BJDebugMsg(I2S(unitCount))
endif

endfor

When the vJass code will be converted to jass code the result will be exactly the same, but it is simply less verbose and error prone.

3. ### ALTELMA

Joined:
Jan 4, 2009
Messages:
113
Resources:
0
Resources:
0
If I don't want use vJass, but I want use basic jass my Code is OK?

Joined:
Jul 14, 2011
Messages:
3,190
Resources:
0
Resources:
0
Yes it's

5. ### ALTELMA

Joined:
Jan 4, 2009
Messages:
113
Resources:
0
Resources:
0
Ahh I'try use that code to count unit on group, but It's doesn't work, why and How I can do fixed it.

Code (vJASS):

function Trig_CountUnitGroup_Actions takes nothing returns nothing

local unit u
local group g =CreateGroup()
local integer unitCount
local integer i

call GroupEnumUnitsInRange(g, 0, 0, 1000000000, null)

loop
set u = FirstOfGroup(g)
exitwhen u == null
set i = i + 1
if(GetUnitTypeId(u) == 'hf00')then
set unitCount =unitCount + 1
call BJDebugMsg("COUNT IS : "+I2S(unitCount))
else
call BJDebugMsg("LOOP :"+I2S(i))
endif
call GroupRemoveUnit(g,u)
endloop
endfunction

//===========================================================================
function InitTrig_CountUnitGroup takes nothing returns nothing
set gg_trg_CountUnitGroup = CreateTrigger()
call TriggerRegisterPlayerChatEvent(gg_trg_CountUnitGroup, Player(0), "-uc", true)
call TriggerAddAction( gg_trg_CountUnitGroup, function Trig_CountUnitGroup_Actions )
endfunction

Tell me plz!!

6. ### Spartipilo

Joined:
Jul 14, 2011
Messages:
3,190
Resources:
0
Resources:
0
Are the 'hf00' units in the map? else it wont do anything.

Also, you have to destroy g and null u.

7. ### ALTELMA

Joined:
Jan 4, 2009
Messages:
113
Resources:
0
Resources:
0
Code (vJASS):

function Trig_CountUnitGroup_Actions takes nothing returns nothing

local unit u
local group g =CreateGroup()
local integer unitCount
local integer i

call GroupEnumUnitsInRange(g, 0, 0, 1000000000, null)

loop
set u = FirstOfGroup(g)
exitwhen u == null
set i = i + 1
if(GetUnitTypeId(u) == 'hf00')then
set unitCount =unitCount + 1
call BJDebugMsg("COUNT IS : "+I2S(unitCount))
endif
call GroupRemoveUnit(g,u)
endloop

call DestroyGroup(g)
set g -= null
endfunction

//===========================================================================
function InitTrig_CountUnitGroup takes nothing returns nothing
set gg_trg_CountUnitGroup = CreateTrigger()
call TriggerRegisterPlayerChatEvent(gg_trg_CountUnitGroup, Player(0), "-uc", true)
call TriggerAddAction( gg_trg_CountUnitGroup, function Trig_CountUnitGroup_Actions )
endfunction

I don't know why don't display text in loop or loop is infinite?

'hfoo' is footman they have really.

8. ### Spartipilo

Joined:
Jul 14, 2011
Messages:
3,190
Resources:
0
Resources:
0
'hf00' is nothing.
'hfoo' is footman.

Also (I just noticed this) If the local integer variable has no value it will mess the whole thing. It's probably doing the Enum but not displaying any message, since the message to display contains "null", which I tough should be naturally 0 but now noticed that isnt.

Code (vJASS):

local unit u
local group g =CreateGroup()
local integer i = 0

call GroupEnumUnitsInRange(g, 0, 0, 1000000000, null)

loop
set u = FirstOfGroup(g)
exitwhen u == null
set i = i + 1
if(GetUnitTypeId(u) == 'hfoo')then
set i = i + 1
call BJDebugMsg("COUNT IS : " + I2S(i))
endif
call GroupRemoveUnit(g,u)
endloop

call DestroyGroup(g)

9. ### ALTELMA

Joined:
Jan 4, 2009
Messages:
113
Resources:
0
Resources:
0
OK I get it all,Thanks a lot...

Last edited: May 4, 2012