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

Find Unit ID Handle in Hashtable?

Status
Not open for further replies.
Level 6
Joined
Jul 29, 2011
Messages
90
I apologize if this seems a silly question, but hashtables are fairly new to me, and they honestly give me a huge headache to try to fully figure out. Granted, I've come a long way in my understanding of them, but there's a feature about them that I would very much like to utilize, but I don't know how or if I even can.

What I would like to know is whether or not there is a way to scan a hashtable to find out in which value a particular unit's ID Handle has been stored. Maybe something like:

"Check Hashtable for Triggering Unit's ID Handle and store the matching keys' value in VariableX and VariableY."

I find the vocabulary involved with hashtables to be kind of esoteric as well, so like I said, I apologize if this seems like a silly question, but I can't see a means of utilizing a non-finitely generated custom birth animation and actually being able to account for cancellations without such a function, and I can't seem to find it. Or, if I have found it, then I didn't understand what I found, and therefore didn't realize that I'd found it.

Thanks for any help in regards to this.

EDIT: Something that would allow me to define one of the two hashtable keys, and then scan the other hashtable key for the matching slot that's tied to triggering unit (as triggering unit has already had its ID saved in a hashtable in a different trigger, but there are many different related unit IDs in said hashtable, and so it needs to know which one to reference) would be good as well.

EDIT: It occurs to me that I should offer more information on how the whole thing is working so far.

So the goal here is that I have stationary units which "evolve" into regular units (very much akin to the Zerg Larvae from Starcraft). When the "upgrade" begins from egg to unit, the model changes from egg model to unit model at the *start* of the upgrade instead of *after* it. So I'm applying something of a "custom birth animation" for these units during the hatching cycle. The way it's working is thusly:

Event:
- A unit begins an Upgrade
Conditions:
- Or (Any Conditions are true)
- - Conditions:
- - - Unit type of Triggering Unit equal to PossibilityA
- - - Unit type of Triggering Unit equal to PossibilityB
- - - Etc.
Actions
- If (All conditions are true)
- - Conditions:
- - - Unit type of Triggering Unit equal to PossibilityA
- - Then:
- - - Set: HatchingCount_PossibilityA = HatchingCount_PossibilityA + 1
- - - Create Animation at Location of Triggering Unit using EggAnimation
- - - Hashtable: Store EffectID of Last Created Special Effect in (HatchingCount_PossibilityA of 0 in EggsEffectTable)
- - - Set: HatchingUnitID_PossibilityA = HatchingUnitID_PossibilityA + 1
- - - Hashtable: Store UnitID of TriggeringUnit in (HatchingUnitID_PossibilityA of 0 in EggsUnitTable)
- - - If (All conditions are true)
- - - - Conditions:
- - - - - HatchingCount_PossibilityA Greater than 1
- - - - Then:
- - - - - Set: HatchingAdditional_PossibilityA equal to HatchingAdditional_PossibilityA + 1
- - - - Else:
- - - - - Do Nothing
- - - Animation: Change Triggering Unit's Vertex coloring to 100% 100% 100% with 100% transparency
- - - Wait (insert PossibilityA's build time here)
- - - Animation: Change (Load (HatchingUnitID_PossibilityA - HatchingAdditional_PossibilityA) of 0 in EggsUnitTable) to (insert PossibilityA's tinting %s here) with 0% transparency
- - - Animation: Destroy (Load (HatchingCount_PossibilityA - HatchingAdditional_PossibilityA) of 0 in EggsEffectTable)
- - - Animation: Play Triggering Unit's birth Animation
- - - Set Rally Point for Triggering Unit to (Load 1 of (Owner of Triggering Unit's Player Number) in EggsRallyPointTable) (defined in a different trigger whenever a player uses the rally point ability)
- - - Unit: Order Triggering Unit to move to Rally Point of Triggering Unit as a point
- - - If: (All conditions are true)
- - - - Conditions:
- - - - - HatchingAdditional_PossibilityA greater than 0
- - - - Then:
- - - - - Set: HatchingAdditional_PossibilityA equal to HatchingAdditional_PossibilityA - 1
- - - - Else:
- - - - - Set: HatchingCount_PossibilityA equal to 0
- - - - - Set: HatchingUnitID_PossibilityA equal to 0

And then it repeats with every other unit possibility, with every instance of "PossibilityA" changed with its respective possibility, and with every instance of "of 0" that appears in a Hashtable being changed to its respective number (Possibility B would yield "of 1" for example).

Now the problem I'm having, specifically, is that I'm beginning the "Event - A unit cancels an upgrade" trigger, and I have no idea how to have it find out which animation to destroy unless I can scan a hashtable to find which value of the first key that has the triggering unit's ID saved to it. I hope that someone out there can help with this.

EDIT: Corrected a mistake in the above coding transcription.

EDIT: In case of confusion, I want to point out that I did not post this in "Triggers and Scripts" because it's not the above coding that I'm having any problems with. It's a fresh trigger that I'm inquiring about which is simply related to the above trigger, and I don't know how to get it started.
 
Last edited:
Ah I see. It seems like you're looking for a unique way to represent a unit. If only there was some sort of existing ID, unique to each unit, that could be used as a key...

THERE IS! The function "Key of (Triggering unit)" actually reads a particular handle's internal ID. Let me explain how it works:

When any handle is created (just think of a handle as an object for now. there is a more specific definition, but don't worry about it), it gets a unique ID. It starts at 1048576, and goes up 1 for each new object. When one is recycled, that ID is freed and reused later.

So let's say you create two units: one unit might get 1048772 and the other maybe 1048780. But the fact is: the ID's are unique. And Blizzard gave us a way to access that ID with the "Key" function (this function can't be properly used with JassNewGenPack, but it should work fine with the regular editor).

So that is probably what you're looking for. Instead of assigning a unit a unique key in the hashtable, determined by some integer variable, just use the unique key that Blizzard already gave you (known as the "handle ID").

----

As for your issue, if you want an alternative way to solve it, you can always assign the key to the unit's user data. Then you can load the user data to retrieve the unit's key. But this method interferes with unit indexers (these are systems on the hive, commonly used by spells or other systems), so it isn't the best option if you plan on using spells/systems from the hive.
 
Level 6
Joined
Jul 29, 2011
Messages
90
It worked! Thanks so much! ^_^

For anyone coming upon this post who's interested to know exactly what I did, I simply made it so that every time that the effect ID gets stored in a hashtable in the trigger coding above, it stores the unit ID KEY of triggering unit in another hashtable, and then in the cancellation trigger, I just have it delete special effect at "key of Triggering Unit's Unit ID of 0" in said new hashtable.

I still have the tinting problem, but I'm pretty sure I can work that out. Thanks so much for your help, PurgeandFire. <3
 
Status
Not open for further replies.
Top