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

Hashtable Values

Status
Not open for further replies.
Level 7
Joined
Jul 20, 2009
Messages
295
Hello,

Does it really matter which one of the 2 values I use?
E.g. would it make a difference if I use:
Save x as key(unit) of 0 OR
Save x as 0 of key(unit)?

Edit:
And if I want to save another value for the same unit do I just change the 0 to 1 for example?
And should I clear the child/parent of the unit and if I don't it will leak?
 
Level 7
Joined
Jul 20, 2009
Messages
295
Yes and No

Yes, for handles. This will allow you to overwrite child handles when saving it to hashtables.

No, because strings, integers, reals and booleans cannot overwrite themselves.


Don't be scared of using keys, keys has a maximum size/limit of 2^31

Could you explain more please?
Also I edited my first post.

What is the name of the First value and the Second one? is it Parent -> Child?
If I reset Child, does that mean all of it's first values are reset OR all of the child values are reset of a saved Hashtable?
 
Level 7
Joined
Jul 20, 2009
Messages
295
Here it is to explain

Value - Child - Parent - Hashtable

This answers alot ^^
Now just 1 more left.

If I Save real as 0 of key(unit) in Hash
then Save integer as 0 of key(unit) in Hash
then Save HandleID(unit2) as 0 of key(unit) in Hash

will they overwrite each other? or I have to do it as follows:
Save real as 0 of key(unit) in Hash.
Save integer as 1 of key(unit) in Hash.
Save HandleID(unit2) as 2 of key(unit) in Hash.
 
Level 7
Joined
Jul 20, 2009
Messages
295
As I have explained above, strings, reals, integers and booleans won't overwrite each other. For the handles(units, effects, ability, region,etc) they will overwrite(but not strings, reals, integers, and booleans) because they have the same parent type.

Thanks. ^^

I got a query about how to load values of a casting unit from a dummy unit if you don't mind helping me.

Idea:
Once a unit begins channeling, save name of ability being cast, save caster and target, Create a dummy which dies after 3 seconds.
After dummy dies, If ability name is Cure then Heal target by 12xIntelligence of Caster
  • Start Casting
    • Events
      • Unit - A unit Begins channeling an ability
    • Conditions
      • (Ability being cast) Not equal to Status
    • Actions
      • Set hashunit = (Triggering unit)
      • Custom script: set udg_handle = udg_hashunit
      • Hashtable - Save (Name of (Ability being cast)) as 0 of (Key handle) in Hashtable
      • Hashtable - Save Handle Of(Triggering unit) as 0 of (Key handle) in Hashtable
      • Hashtable - Save Handle Of(Target unit of ability being cast) as 1 of (Key handle) in Hashtable
      • Unit - Create 1 Wisp [Casting] for (Owner of (Triggering unit)) at TempLocation2 facing Default building facing degrees
      • Unit - Add a 3.00 second Generic expiration timer to (Last created unit)
      • Custom script: call RemoveLocation(udg_TempLocation)
      • Custom script: call RemoveLocation(udg_TempLocation2)
  • Spell Effect
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Wisp [Casting]
    • Actions
      • -------- Check if Ability is Cure --------
      • -------- Then --------
      • Unit - Set life of Target to ((Life of Target) + (12.00 x (Real((Intelligence of Caster (Include bonuses))))))
      • -------- Else --------
      • -------- (Do nothing) --------
 
Level 7
Joined
Jul 20, 2009
Messages
295
If you want a shortcut, you can just set the key by set udg_Key = GetHandleId(udg_hashunit)
Because it is much faster

Alright, so I use this custom script in the second trigger? Then what? how to load the ability name, caster and target from this custom script? But wait, hashunit is a temporary variable, e.g. there will be more than 1 unit casting a time.
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
Usually it is better to save x as 0 of Key(unit) since when flushing a child hashtable, you use the parent key.

For example

Save x as 0 of Key(unit)
Save y as 1 of Key(unit)
Save z as 2 of Key(unit)
Save v as 3 of Key(unit)
Flush child hashtable with Key(unit) -> x,y,z,v will be erased.

Save x as Key(unit) of 0
Save y as Key(unit) of 1
Save z as Key(unit) of 2
Save v as Key(unit) of 3
Flush child hashtable with 0 -> only x will be erased.
 
Status
Not open for further replies.
Top