• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

Simple question about group

Status
Not open for further replies.
Level 23
Joined
Feb 6, 2014
Messages
2,466
Hello hivers,

Which do you think is better? For me it looks option B is better but I want to be sure. Also, I haven't tested yet if option B will work.

OPTION A: I create, assign new members and destroy group afterwards everytime
[jass=Option A]
function ...
local group g = CreateGroup()
call GroupEnumUnitsInRange(g, x, y, 200, null)
loop
//Some actions here
endloop
call DestroyGroup(g)
endfunction
[/code]


OPTION B: I emptied the global group and assign new members everytime I use it
[jass=Option B]
globals
private group g = CreateGroup()
endglobals

function ...
call GroupClear(g)
call GroupEnumUnitsInRange(g, x, y, 200, null)
loop
//Some actions here
endloop
endfunction
[/code]
 
Level 25
Joined
Sep 26, 2009
Messages
2,382
I would say option A is better since it uses local variables, meaning there is no way for you to accidentally replace units inside group g for other units. Such thing is possible to happen in option B, but is of course not guaranteed - that depends on if you use group g as temporal variable or not.
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
Option B is better choice if you don't need to keep your units in group later(lets say you just want to damage some units), you also don't need GroupClear because GroupEnumUnits already clears group before adding new units.
 
Level 23
Joined
Feb 6, 2014
Messages
2,466
I would say option A is better since it uses local variables, meaning there is no way for you to accidentally replace units inside group g for other units. Such thing is possible to happen in option B, but is of course not guaranteed - that depends on if you use group g as temporal variable or not.
Nichilus gives a good answer.

Option A : null the local.

The group is only temporary and I will not use it in any other trigger that's why I destroyed it immediately.
Forgot to null the group.
Your opinions remain unchanged?


Option B is better choice if you don't need to keep your units in group later(lets say you just want to damage some units), you also don't need GroupClear because GroupEnumUnits already clears group before adding new units.
But what if some trigger does use the global group g but does not empties the group like
JASS:
   call GroupClear(g)
   call GroupEnumUnitsInRange(g, x, y, 200, null)
   if FirstOfGroup(g) != null
     //DO DAMAGE TO FIRST UNIT IN GROUP
   endif
Your opinion remains unchanged?


For all enums in jass 1 global is enough, which is never destroyed.
So the group should not be private. I agree having 1 global group for temporary group actions is better but I'm just not sure if the GroupClear(g) is better than Create and Destroy Group.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Well...
Option A is safe as g will never be overwritten by another function.
Option B is more efficient but has that danger.

GroupUtils iirc is meant to do option B and remove that danger.
I think it also gave them an integer in a hashtable but that I am not really sure of.
As many people use FoG iterations, maintaining the group is hard.

Also, if a group contains units, and you call GroupEnumUnits(), you clear the group automatically.
I dont really know if that is very usefull or not though.

So either use something like GroupUtils, or use option A.
Always make sure that nothing can ever go wrong.
 
Level 23
Joined
Feb 6, 2014
Messages
2,466
Well...
Option A is safe as g will never be overwritten by another function.
Option B is more efficient but has that danger.

GroupUtils iirc is meant to do option B and remove that danger.
I think it also gave them an integer in a hashtable but that I am not really sure of.
As many people use FoG iterations, maintaining the group is hard.

Also, if a group contains units, and you call GroupEnumUnits(), you clear the group automatically.
I dont really know if that is very usefull or not though.

So either use something like GroupUtils, or use option A.
Always make sure that nothing can ever go wrong.

Thanks, I will stick with GroupUtils.
http://www.hiveworkshop.com/forums/graveyard-418/system-grouputils-205251/

+rep to all
 
Status
Not open for further replies.
Top