• 🏆 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!

[Solved] How do I create an empty group?

Status
Not open for further replies.
Level 6
Joined
Dec 31, 2017
Messages
138
I have a piece of code:
  • Custom script: call DestroyGroup (udg_Temp_Group)
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • Range more or equal 0.00
    • Then - Actions
      • Set Temp_Group = (Units within Range of Temp_Point matching...)
    • Else - Actions
      • Set Temp_Group = (Units in (Region(0.00, 0.00, 0.00, 0.00)))
      • If (Range equals -1.00) then do (Group - Add (Target unit of ability being cast) to Temp_Group) else do (Do nothing)
      • If (Range equals -2.00) then do (Group - Add (Triggering unit) to Temp_Group) else do (Do nothing)
I know I can fix leaks in "Set Temp_Group = (Units in (Region(0.00, 0.00, 0.00, 0.00)))" but I'm seeking for a better way to do this.
 
Level 6
Joined
Dec 31, 2017
Messages
138
A non-array unit group created from the Variable editor is always initialized as empty. Array unit groups are initialized as empty up until the size you define it as. After the size, they are null, so you have to manually create the group by using the script posted by HappyTauren.
It doesn't help with groups (Temp_Group) that are being created and destroyed in every trigger. For global static (e.g. group that contains all dummy units and never gets destroyed) it does help.
I use Set Unit Group = All Units in Region (No region for the region)
and then use Remove all Units from Unit Group.

Worked perfectly fine so far & I am still using it.
Yes, I've forgot that I can Remove all units from Temp_Grop instead of destroying it. But both versions work fine.
 
Level 6
Joined
Dec 31, 2017
Messages
138
So I use it like this:
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • Range more or equal 0.00
    • Then - Actions
      • Custom script: call DestroyGroup (udg_Temp_Group)
      • Set Temp_Group = (Units within Range of Temp_Point matching ...)
    • Else - Actions
      • Group - Remove all units of Temp_Group from Temp_Group
      • If (Range equals -1.00) then do (Group - Add (Target unit of ability being cast) to Temp_Group) else do (Do nothing)
      • If (Range equals -2.00) then do (Group - Add (Triggering unit) to Temp_Group) else do (Do nothing)
?
 
Level 6
Joined
Dec 31, 2017
Messages
138
I'm a little confused with the purpose of the trigger you're posting. Could you go more in-depth with what you're trying to do and to post all the triggers associated with it?
I'm creating an invisibility spell that target caster (lvl 1), single unit (lvl 2) and area (lvl 3&4).
I have 1 main ability with hidden icon and 3 dummy abilities (that have suitable behavior) that are added/removed from the hero at leveling the main ability up.

Every level of the spell has it's range stored in invis_range[] array. -2.0 is used for caster only and -1.0 for target only. I set variable Range corresponding value.

Provided fragment should put all affected units into Temp_Group.

Then for every unit of this group I create a dummy unit and so on.
----------------------

The fragment above though doesn't work as Temp_Group is destroyed in literally every trigger.
 
Level 6
Joined
Dec 31, 2017
Messages
138
But why bother to create a group and THEN remove the units? there are two scenarios:

1. The group is already empty
2. The group is not empty

If 1, do nothing
If 2, remove units from group
3rd scenario:
There is no actual group and you have to create it first.
It might be after "call DestroyGroup()" or group variable set NULL.
 
Level 11
Joined
Jun 2, 2004
Messages
849
The problem is that GUI often creates new groups for you instead of allowing you to populate an existing one. Starting from an empty group is the uncommon case. So most people just destroy the group in their temporary unit group variable instead of leaving it to be reused later (which will most likely leak).
 
There is no actual group and you have to create it first.
It might be after "call DestroyGroup()" or group variable set NULL.
Not in GUI. If the variable exist, there is an empty group.

Though I'll admit that I did not consider a destroyed group.
That was exactly why Shar said:
I use Set Unit Group = All Units in Region (No region for the region)
and then use Remove all Units from Unit Group.
First operation creates a group via GUI. Second operation ensures group is empty. What you end up with is having created a new, blank unit group.
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183
True, but once again it seems like an odd scenario.

If you want to reuse a group for whatever reason, just remove the units, do not destroy the group.

I cannot think of any scenario where it would actually be the best option to destroy a group>make a new one>remove units from it

Something about that rubs me the wrong way.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
It's always better to recycle the groups rather than create and destroy it everytime.
As far as I can tell destroying groups is completely leakless. Recycling them likely has a larger overhead then simply creating and destroying them as required.
Not in GUI. If the variable exist, there is an empty group.
Not for array indices past the size value.
First operation creates a group via GUI. Second operation ensures group is empty. What you end up with is having created a new, blank unit group.
It is worth noting that this is a very bad/hacky way of making a unit group. It Is far better to use a line of custom script to create unit groups. One eventually realizes one needs so many lines of custom script to do stuff that one is better off writing JASS directly.
 
Status
Not open for further replies.
Top