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

Unitgroups and hashtables?

Status
Not open for further replies.
Level 19
Joined
Feb 4, 2009
Messages
1,313
How to save a unitgroup in a hashtable and how to add more units to it?
I'm interested in leakless ways to do this so I do NOT want to destroy a unitgroup every time I add a unit

And if there is an alternative to saving units in a hashtable when making something like the following I'd like to know it as well:

pick all units in group blah
set i = id of picked unit
damage all units in (load group with key 0 and i)

edit:
tested a few things myself and it seems like saving a unitgroup to a hashtable does not save the unitgroup but a reference to the group instead
for example:
  • Ini
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set g = (Units of type Footman)
      • Hashtable - Save Handle Ofg as 0 of 0 in (Last created hashtable)
      • Game - Display to (All players) for 20.00 seconds the text: (String((Number of units in (Load 0 of 0 in (Last created hashtable)))))
      • Unit Group - Remove all units from g
      • Game - Display to (All players) for 20.00 seconds the text: (String((Number of units in (Load 0 of 0 in (Last created hashtable)))))
      • Unit Group - Add Footman 0005 <gen> to (Load 0 of 0 in (Last created hashtable))
      • Game - Display to (All players) for 20.00 seconds the text: (String((Number of units in (Load 0 of 0 in (Last created hashtable)))))
      • Custom script: call DestroyGroup(udg_g)
      • Game - Display to (All players) for 20.00 seconds the text: (String((Number of units in (Load 0 of 0 in (Last created hashtable)))))
will display 4 0 1 0
so hashtable unitgroups have to be destroyed and can't be recycled most likely :/
 
  • Unit Group - Remove all units from g
This action is pointless. You pick units that were automatically assigned to the "g" group and you remove them afterwards. This action should be used on unit groups that were manually assigned units within. So, if you make the same pick (Units of type Footman), it will normally return the same results.

You can normally create a Unit Group variable and add the units in there. E.g.
  • Trigger
  • Events
    • Unit - A unit starts the effect of an ability
  • Conditions
  • Actions
    • Set Point1 = (Position of (Triggering unit))
    • Hashtable - Save handle of TempGroup as (Key(group)) of (Key(Triggering unit)) in Hashtable
    • Custom script: set bj_wantDestroyGroup = true
    • Unit Group - Pick every unit in (Units within 300.00 of Point1 matching ((Owner of (Matching unit)) Equal to (Owner of (Triggering unit)) and do (Actions)
      • Loop - Actions
        • Unit Group - Add (Picked unit) to (Load (Key(group)) of (Key(Triggering unit)) in Hashtable)
    • Custom script: call RemoveLocation (udg_Point1)
  • Trigger2
  • Events
    • Unit - A unit dies
  • Conditions
    • ((Key(group)) is stored as a Handle of (Key(Triggering unit)) in Hashtable) Equal to True
  • Actions
    • Unit Group - Pick every unit in (Load (Key(group)) of (Key(Triggering unit)) in Hashtable) and do (Actions)
      • Loop - Actions
        • Unit - Kill (Picked unit)
    • Hashtable - Clear all child hashtables of (Key(Triggering unit)) in Hashtable
This trigger will kill every unit that was temporarily assigned to the special group of the caster.
 
Level 18
Joined
Feb 28, 2009
Messages
1,970
Data in hashtables are... umm, well, more 'pointers' than data itself.
Just like here: Hashtable - Save Handle Ofg as 0 of 0 in (Last created hashtable)
You save the Handle of group. Not the data in group. So when group is destroyed the data also. So in hashtables you should also use static groups.
 
Level 19
Joined
Feb 4, 2009
Messages
1,313
  • Unit Group - Remove all units from g
This action is pointless. You pick units that were automatically assigned to the "g" group and you remove them afterwards. This action should be used on unit groups that were manually assigned units within. So, if you make the same pick (Units of type Footman), it will normally return the same results.

of cause it's pointless
as I already mentioned it was a test to see how things work

You can normally create a Unit Group variable and add the units in there. E.g.
  • Trigger
  • Events
    • Unit - A unit starts the effect of an ability
  • Conditions
  • Actions
    • Set Point1 = (Position of (Triggering unit))
    • Hashtable - Save handle of TempGroup as (Key(group)) of (Key(Triggering unit)) in Hashtable
    • Custom script: set bj_wantDestroyGroup = true
    • Unit Group - Pick every unit in (Units within 300.00 of Point1 matching ((Owner of (Matching unit)) Equal to (Owner of (Triggering unit)) and do (Actions)
      • Loop - Actions
        • Unit Group - Add (Picked unit) to (Load (Key(group)) of (Key(Triggering unit)) in Hashtable)
    • Custom script: call RemoveLocation (udg_Point1)
  • Trigger2
  • Events
    • Unit - A unit dies
  • Conditions
    • ((Key(group)) is stored as a Handle of (Key(Triggering unit)) in Hashtable) Equal to True
  • Actions
    • Unit Group - Pick every unit in (Load (Key(group)) of (Key(Triggering unit)) in Hashtable) and do (Actions)
      • Loop - Actions
        • Unit - Kill (Picked unit)
    • Hashtable - Clear all child hashtables of (Key(Triggering unit)) in Hashtable
This trigger will kill every unit that was temporarily assigned to the special group of the caster.

and if the ability is casted again it will leak a group?

Data in hashtables are... umm, well, more 'pointers' than data itself.
Just like here: Hashtable - Save Handle Ofg as 0 of 0 in (Last created hashtable)
You save the Handle of group. Not the data in group. So when group is destroyed the data also. So in hashtables you should also use static groups.

this matches with what I've found out so I think it is true
but what are static groups?

thanks to both of you
 
Static groups are groups that you will never set them through the variable action, but you will just create the variable.
Let's say you create a Unit Group variable. That is temporarily static. If you go through:
Set UnitGroup = XX (UnitGroup being the variable we just created), it's no longer "static". 'Static'-flagged is just some global group used to only add and remove units.

To answer the other question:
D4RK_G4ND4LF said:
and if the ability is casted again it will leak a group?
No, since you don't set it in a variable through the Set Variable action, so it will not leak.

Let's see another example. You create a timer variable. If you set "Set Timer1 = (Last started timer)", that will leak, because you set it in a variable and it will require the DestroyTimer call. If you do this: Countdown Timer - Start Timer1 as a one-shot timer, that action will not leak the countdown timer, because you didn't previously set it to a variable.
 
Level 19
Joined
Feb 4, 2009
Messages
1,313
Static groups are groups that you will never set them through the variable action, but you will just create the variable.
Let's say you create a Unit Group variable. That is temporarily static. If you go through:
Set UnitGroup = XX (UnitGroup being the variable we just created), it's no longer "static". 'Static'-flagged is just some global group used to only add and remove units.

To answer the other question:

No, since you don't set it in a variable through the Set Variable action, so it will not leak.

Let's see another example. You create a timer variable. If you set "Set Timer1 = (Last started timer)", that will leak, because you set it in a variable and it will require the DestroyTimer call. If you do this: Countdown Timer - Start Timer1 as a one-shot timer, that action will not leak the countdown timer, because you didn't previously set it to a variable.

I just tested it and it leaks
(it is the destroying of the group that leaks so it is quite hard to deal with it in GUI)

and I also copied your trigger and it seems like it is not MUI which renders it useless for spells
I guess that's because both hashtables save to the same group handle
It works fine with CreateGroup() though
 

Attachments

  • Test.w3x
    14.5 KB · Views: 45
Level 18
Joined
Feb 28, 2009
Messages
1,970
Static group is once created at map init (if using it with GUI you create it in variable editor only) and you never store it again. You just add/remove units to it so the group does not leak.
(It`s the way of making MUI spells with hashtables)
 
Status
Not open for further replies.
Top