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
508
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
610
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
610
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
610
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.
  • 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 The Helper:
    I think we need to add something to the bottom of the front page that shows the Headline News forum that has a link to go to the News Forum Index so people can see there is more news. Do you guys see what I am saying, lets say you read all the articles on the front page and you get to the end and it just ends, no kind of link for MOAR!
  • The Helper The Helper:
    Happy Wednesday!
    +1
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    Sticking with the desserts for now the latest recipe is Fried Apple Pies - https://www.thehelper.net/threads/recipe-fried-apple-pies.194297/
  • The Helper The Helper:
    Finally finding about some of the bots that are flooding the users online - bytespider apparently is a huge offender here - ignores robots.txt and comes in from a ton of different IPs
  • Monovertex Monovertex:
    @The Helper I'm really not seeing the "Signature" link in the sidebar on that page. Here's a screenshot:
  • The Helper The Helper:
    I have reported it - I was wondering why nobody I have given sigs to over the last few years have used them
  • The Helper The Helper:
    Ghan has said he has fixed this. Monovertex please confirm this fix. This was only a problem with people that had signatures in the upper levels like not the special members but the respected members.
  • The Helper The Helper:
    Here is a better place to manage this stuff https://www.thehelper.net/account/account-details which I think should be way more visible
  • The Helper The Helper:
    I am hoping that online user count drop is finally that TikTok bot banned
  • Ghan Ghan:
    I added the filter last night.
  • The Helper The Helper:
    They are still there

      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