First of group vs. ForGroup II

Vexorian

Why no custom sig?
Reaction score
187
I dunno why that thread was closed. But I had to say this.

Let me say this, FirstOfGroup is faster than ForGroup when you don't need to keep the group after the iteration.

Else it is slower.

But the difference is negligible and FirstOfGroup has the advantage of not using another function so code looks more structured and you can easily use local variables without going through the work of passing them using bridge globals.

In fact, using bridge globals may as well make ForGroup heavier.

But if you ask me, I would rather not use groups at all, when you use ForGroup it means you want an iteration and groups are bad for that. And I have seen issues arise with FirstOfGroup if there are waits between the loop and one unit dies.

It is all easier to use a "dynamic array". Unit group is barely useful for IsUnitInGroup, and that's not so useful either. I am lately just using groups for quick detections in areas and ranges but never to actually store groups of units for later use.

BTW, the old benchmark ForGroup benchmark didn't use GetEnumUnit so it could as well be flawed.
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
And if speed is not what you want, use the method you like more - the one which is more convenient.
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
Thanks for the info Vex.

Well, I don't think this'll be a problem anymore. This should probably be stickied.
 

ReVolver

Mega Super Ultra Cool Member
Reaction score
609
I guess this will prevent the future arguments about groups.

[Thread Stuck]
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
Stickied?
There are tons of helpful posts / threads in the Jass forum. If they were all stickied you would have to dive deep to find questions around here. Like all helpful threads, I remember them, if someone is asking a question refering to this, I'll point it out.

No need to sticky is one in my opinion. But, of course, I'm no moderator.

By the way Vexorain, would you mind explaining why exactly is that so? And how did you come to that conclusion?
 

ReVolver

Mega Super Ultra Cool Member
Reaction score
609
Well we should have at least add it to the "The JASS Forum" thread so we can won't have any problem or fights over which group method is better.
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
There are lots and lots of arguements in Jass. Most of them were answered, yet new threads pop around asking the same question over and over becuase people don't bother searching. Does it mean we should sticky every answer to every arguement? In my opinion no, just point out the place with the answer, that is why we come to TH, to help. :p
 

ReVolver

Mega Super Ultra Cool Member
Reaction score
609
You got a point there but if only all the member can just read the sticky threads and the WE-Tutorial site.
 

Cohadar

master of fugue
Reaction score
209
It is all easier to use a "dynamic array".

I agree with this but it is not possible always.
Sure when you make say a spell that has some periodic timer manipulation of units, using arrays is almost always best solution.

But when you want to cast some spell on all units in an area for example you simply have to use groups.

After all, all GetUnitsInA... functions return groups.

I personally have never used loops for groups.

First because it is in my opinion ugly, I would always prefer two smaller functions over a single long one, it makes the code easier to understand.

Second because it destroys the group and I usually need it after that.

Sure passing global params can be a hussle, but I usually declare them just above ForGroup handler function so than I have the advantage of always knowing what are the parameters that I need when dealing with that group.

And since those parameters are usually locals in function that calls ForGroup
I then can remove those locals and use globals directly.
So there is no passing of arguments :)

JASS:

//===========================================================================
globals
    // global ForGroup parameters
    private group gp_group
    private unit gp_hero
    private integer gp_level
endglobals

//===========================================================================
private function GroupStun takes nothing returns nothing
    local real x2 = GetUnitX(gp_hero)
    local real y2 = GetUnitY(gp_hero)
    //---- 
    set lift = DeltaImpulse.create(GetEnumUnit(), 0.0, 0.0, 300.0 + AOE(gp_level) - distance)
    //---- 
endfunction

//===========================================================================
//  In spell Actions I am using gp_ globals directly, no need for locals
//===========================================================================
private function Actions takes nothing returns nothing
    set gp_hero = GetTriggerUnit()
    set gp_group = NewGroup() // Recycler
    set gp_level = GetUnitAbilityLevel(gp_hero, AID_WAR_STOMP)
    //----   
    call GroupEnumUnitsInRange(gp_group, x, y, AOE(cdata.level), Condition(function GroundEnemyCondition))
    call ForGroup(gp_group, function GroupStun)
    //----
endfunction


//---- lines represent code I removed for simplicity

So if you ask me: ForGroup > First of group
 

juty

Zoom out problems look smaller
Reaction score
26
There are lots and lots of arguements in Jass. Most of them were answered, yet new threads pop around asking the same question over and over becuase people don't bother searching. Does it mean we should sticky every answer to every arguement? In my opinion no, just point out the place with the answer, that is why we come to TH, to help. :p

Easy to fix that don’t let users join the website until they activate there account by email and say in email to search form first because things are quicker this way saves time I recon
 

NetherHawk

New Member
Reaction score
26
hmmm, i use a mixture of both, it depends on your spell actually yes? and what you are trying to achieve. In certain cases, forGroup really is faster. in instances where you only need to use the group once.
 

Vexorian

Why no custom sig?
Reaction score
187
But when you want to cast some spell on all units in an area for example you simply have to use groups.

You can just use the boolexpr argument of any of the GroupEnum functions to do the iteration or even add them to the unit array.

After all, all GetUnitsInA... functions return groups.
I wouldn't really use any of those GetUnitsIn BJ functions, they most likely keep creating a group, or don't null something/etc. And since GroupEnum functions are pretty messed up when you use a group that is not permanent it is not good to use them.



I personally have never used loops for groups.
First because it is in my opinion ugly, I would always prefer two smaller functions over a single long one, it makes the code easier to understand.
Second because it destroys the group and I usually need it after that.

And that just about does not make much sense, if GroupEnums are the only good reason to use groups, you don't really need to keep the group. You will have to detect again, otherwise, use your iterating method to store units in an array, linked list, whatever that isn't a group.

--
My conclusion is that both ForGroup and FirstOfGroup mean that you are actually using groups for something that is not detecting units in rect or range, and therefore could be replaced by better things.

When I need to enumerate units in range or rect I just use a boolexpr, ever since we found out that Condition always makes the best handle it just got easier to use just Enum than Enum + ForGroup . Less lines, and still two functions, quite fun. And when I use Enums I use the same ENUMGROUP group global variable so I don't have issues with them. By having a return false in such group enums I prevent any unit from being added and thus there are less linking and no usage of memory that would otherwise be caused by the usual way that requires both an Enum and a ForGroup .

Out of over-complication I made a function that is like GetUnitsInRangeOfLoc but that takes a dynamic unit array argument to store the units there. It is probably slower than anything else but I minimize the problems with groups.

And I was missing the point here, there are issues with unit groups, and there specially are issues with FirstOfGroup (issues, as if random bugs when a disease cloud is nearby ...) And this is the main reason I just avoid them for storage of units and just use them for detection.
 

Somatic

You can change this now in User CP.
Reaction score
84
Nice Points put out. But if using a dynamic Array for units, How do you do that? Mind showing an example?
 

Doom-Angel

Jass User (Just started using NewGen)
Reaction score
167
what's a private global and private function?
i never heard of those
 

Cohadar

master of fugue
Reaction score
209
You can just use the boolexpr argument of any of the GroupEnum functions to do the iteration or even add them to the unit array.

Now THIS is useful information.
Really nice idea, working on units directly while they are being picked...

I use GroupEnumUnitsInRect and GroupEnumUnitsInRegion + group recycler,
no BJ's there.

Using array is like you said slower in here but with direct boolexpr using it might not be necessary...

Passing of global params with boolexpr is still the same as with ForGroup I believe?

@Doom-Angel:
jassnewgenpack4b\jasshelper\jasshelpermanual.html

EDIT:
Vell Vex I tried this boolexpr thing and I can say I do not like it now.
It is merging together GroupCondition function and a EnumGroupAction functions.
I would always prefer better looking over slightly optimized code,
it simply helps you not make mistakes.
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
> What are the odds of such things happening

About one in a million, which makes them happen nine games out of ten, and the one in ten are those you are playing.
 
Reaction score
456
[Off-Topic]

Some was talking about stickying this thread. I was just thinking that wouldn't it be better to make a "Frequently Asked ("JASS") Questions" thread, where these ("future")helpful posts are collected?
 

N-a-z-g-u-l

New Member
Reaction score
30
There are lots and lots of arguements in Jass. Most of them were answered, yet new threads pop around asking the same question over and over becuase people don't bother searching.

well, that isnt right... somehow the last threads about this topic were closed too early, just before the discussion started...

its funny that a thread created by vexorian will instantly be stickied, even if there are no proofs in it at all... it just a thesis and even should be an answer to another thread...
but well, you seem to trust in vexorian... then sticky it and ignore proven posts...

by the way, is it even possible to call GroupEnumUnitsInRect(null, r, Condition( function ... ) )?

JASS:
function ForUnitsInRect takes rect R, code C returns nothing
    local group G = CreateGroup()
    call GroupEnumUnitsInRect(G, R, Condition( C ) )
    call DestroyGroup( G )
    set G = null
endfunction


and how will it affect performance if i just use no filter ( null? )

EDIT: updated script with a group instead of "null" as group parameter
 

Cohadar

master of fugue
Reaction score
209
Don't use null for a group.
Just use some dummy global group witch you will instantly clear after you enum all units
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top