Unit dies, is hashtable with its values cleaned automatically?

Kuberr24

Well-Known Member
Reaction score
28
If I use a hashtable, and I "attach" some stuff to unit X by using unit X as the parent key, and then unit X dies, will the hashtable clean itself up and remove the parent and all childs associated with it (unit X), or do I have to clean this up manually by using flushparent to prevent the hashtable from cluttering?
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
You have to clean it up yourself. WC3 doesn't magically know that it's matched to a unit - it's simply stored the information in the hashtable keyed to a certain integer number (the unit's handle ID).

In fact, I believe that if the unit's handle ID gets recycled (which I think happens, though I don't know the details of what WC3 does in that regard), it's possible that a unit created later could have the same handle ID and would therefore "adopt" the data that was attached to the removed unit, unless you had cleaned it up.
 

Zwiebelchen

You can change this now in User CP.
Reaction score
60
Actually, you can not "remove" the parent-key and child key. They are always there. Hashtables are nothing else than a two-dimensional array.

The only thing you need to do is flushing the childhashtable when the unit dies.
 

Kuberr24

Well-Known Member
Reaction score
28
So everytime I use a unit as a parentkey in a hashtable, I am forced to flush that parent when the unit dies? Which would basicly result in this trigger to be included in everymap:

Event - A unit dies
Action - FlushChildHashtable(using key(GetTriggeringUnit()) of HashtableVariable)
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
Well, death is not necessarily the end of a unit (corpses, resurrection, etc.)

But that's the gist of it.
 

Kuberr24

Well-Known Member
Reaction score
28
When does the game considers a unit to be totally death? After the 60 second corpse animation is done and the corpse is gone, the unit gets permanently removed?

Also one more side question: Lets say I store a timer in a hashtable using parentKey X and childkey Y. Later on, I destroy that timer. What value is now in the hastable under X,Y ? Still that timer, Or does it get removed? What if i try to load the (destroyed) timer into a local timer variable? Similarly, lets say i flush the entire hashtable and then try to load a timer into a variable, but of course the hashtable doesn't have a timer anymore?


+rep to both of you, thx
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
When does the game considers a unit to be totally death? After the 60 second corpse animation is done and the corpse is gone, the unit gets permanently removed?

That is when the unit is no longer in the game, its handle id is recycled, and it is technically 'removed'. It dies when it dies.

Also one more side question: Lets say I store a timer in a hashtable using parentKey X and childkey Y. Later on, I destroy that timer. What value is now in the hastable under X,Y ? Still that timer, Or does it get removed? What if i try to load the (destroyed) timer into a local timer variable?

It will still hold the pointer to the destroyed timer. It is not null, but neither is it a timer. If you try to load it into a local timer variable, it will probably load a destroyed timer into it.

Similarly, lets say i flush the entire hashtable and then try to load a timer into a variable, but of course the hashtable doesn't have a timer anymore?

The hashtable will return 'null' for nonexistant items. Of course there are the 'HaveSaved____' functions to check to see if anything has been saved under specific keys.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      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