• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Using a single group for everything.

Status
Not open for further replies.
Level 2
Joined
Jun 28, 2010
Messages
20
I am new to JASS and don't know that many commands yet. In my previus post i learned from Dr Super Good that it is possible to use a single group for the whole map, by just re-using it over and over and thus not having to create new groups, since these, even when removed, nullified and/or cleared, causes a leak. I would want to know how to do this, because, the only way i know so far is by creating a group, and adding them to the universal one, which doesn't help in any way. If Dr Super Good or anyone else could tell me how to do this, I would be very gratefull.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
You can use only one static group never destroyed, as long you only need to enum units instantly, and don't need them during time.

Usually, we use a GroupEnum + a null filter, and then a FirstOfGroup/GroupRemoveUnit loop :

JASS:
local unit u

call GroupEnum...(YOUR_STATIC_GROUP,null)
loop
set u = FirstOfGroup(YOUR_STATIC_GROUP)
exitwhen u == null
    // do your stuff here with u
endloop
In case of triggered spells, you would probably remove the caster from the group before remove it (no need to check if it was inside or not).

The reason why we use a null filter (which is equal to a function which takes nothing and returns true) instead of using a "valid" filter, is because it's more efficient, and it doesn't split your code, so you don't have to use temp globals variables, you can keep your locals.
It is more efficient because each enum with a not null filter opens a new thread.

Now, if you need to keep units during time, you have to use several groups, or your own structure, like here.

EDIT : If you use the newest jasshelper by cohadar, you have a nicer loop for that.
(Read the first post of my resource it explains some interesting things)

Also instead of create/destroy groups you can recycle them, but i'm not sure it worths it.

And finally, i have never heard about a permanent leak about destroying groups if it's done properly, however i didn't test it.
 
Level 2
Joined
Jun 28, 2010
Messages
20
Thanks Troll-brain, I'll try that and see if i get how it works. In the best case i can just implant this everywhere i use a group after converting the triggers to JASS. Then I can remove the leak so much easier without having to go into the more advanced codes, I'll save that for C++ :).

Edit: I don't really get how you are supposed to add conditions for the units in the group. Do you add that when you create the group (cause in that case i would still have to create one group for every action, but not when using the same action again so it wouldn't matter for things that happen periodically), or do you check for the unit if it meets the conditions?
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
Thanks Troll-brain, I'll try that and see if i get how it works. In the best case i can just implant this everywhere i use a group after converting the triggers to JASS. Then I can remove the leak so much easier without having to go into the more advanced codes, I'll save that for C++ :).

According to your previous thread if you don't want to use jass, you can still use a custom blizzard.j, to fix inherent GUI leaks, but oh well to edit it correctly, you still have to use jass.

Edit: I don't really get how you are supposed to add conditions for the units in the group. Do you add that when you create the group (cause in that case i would still have to create one group for every action, but not when using the same action again so it wouldn't matter for things that happen periodically), or do you check for the unit if it meets the conditions?

With a null filter, all units are added, then inside the loop you choice which units to handle or not.
It's still faster than a "valid" filter where only the matched units are added (jass is so fun).

Also, each time a GroupEnum... is called, it clears the group and then eventually add units inside, so with this static group you will never have to use GroupClear.
 
Status
Not open for further replies.
Top