• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[Trigger] Help to clean a hashtable for a special trigger

Status
Not open for further replies.
Level 4
Joined
Apr 22, 2020
Messages
53
Hi,

I need help to clean a hashtable.

I want a unit, a fury, to be uncontrollable when you give the order to attack an unit and to create a new unit if she kills her target.

I did 2 triggers :



I put a "clear child hashtable" at the end of the second trigger but I had an issue with it. Indeed, when 2 furies are attacking, only one of them create a unit. (Because there is no more hashtable for the second one)

So I let it without but I see everywhere in this forum that it will leak. And I don't know what to do.

(It's a map for 6 players)
 
Level 4
Joined
Apr 22, 2020
Messages
53
I've add this on the second Trigger (Fury Kill). Does it work to avoid leak ?


Other question :

Is it better to set the hashtable in an other trigger to avoid to create the same hashtable again and again or it doesn't matter ?
 
Level 25
Joined
Sep 26, 2009
Messages
2,388
In my opinion, you should not be creating new hashtable. That way the entire data structure where you saved data (owner of fury) is replaced by new empty data structure.
By default, the hashtable should already be created, so there is no need to re-create it in any trigger.

Now there are a few issues that I noticed in your triggers.
1. In your second trigger, when you create Basic Golem, you load "Team number of OwnerofFury", but the value of OwnerofFury may be changed at this point (it will reference the owner of the last Fury unit set in your first trigger). What you want to use is to load the owner of Killing unit (which will not work at this point, as you remove the Killing unit a few actions before).
So what you need to do is to edit your second trigger, as first action use the "Set OwnerofFury = (Owner of Killing unit)" and then use that when creating Basic Golem.

2. Since all you save in the hashtable is the player number of owner of Fury unit, you do not need to use hashtable at all - as you can see in my point 1, you always have access to owner of fury.
So instead of "Unit - Create 1 Basic Golem for (load xxx from hashtable)", you would add the action from my point 1 and then do "Unit - Create 1 basic Golem for OwnerofFury"

3. I think you are clearing the hashtable wrongly. The data (owning player) from "Fury attack" trigger are saved under handle "Player number", while in the second trigger you clear the hashtable using handle "last created unit". Player number and last created unit will of course have different handles, so you are not cleaning anything.
 
Level 4
Joined
Apr 22, 2020
Messages
53
I immediatly tested it in your way but there is a problem. When I give order to attack to the fury, I set her owner as Neutral to avoid her owner to give her other orders. (That's how I want this to work)
Then, when I use your method, it gives the new golem created to Neutral and not to the first owner of fury.

That's why I used hashtable, to save the first identity of the owner.

But maybe there is another way or I did it wrong cause I misunderstood ^^"

For the third step you told me, do I really have to clean this hashtable ? Because I don't know what I have to clean left except the new golem.

Thanks for your time :)
 
Level 25
Joined
Sep 26, 2009
Messages
2,388
Ah, sorry, I missed the bit where you change it to neutral passive. In that case you are correct - storing the player number is the way to go.
I also double checked what I wrote about not needing to create a hashtable - you actually do need to create the hashtable (but only once), so you would need a trigger like this:
  • Ini Hashtable
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set VariableSet fury_hash = (Last created hashtable)
To save the owner of unit in hashtable:
  • Hashtable - Save (Player number of (Owner of (Triggering unit))) as 0 of (Key (Triggering unit).) in fury_hash.
To load the original owner (here the variable "original_owner" is a player variable):
  • Set VariableSet original_owner = (Player((Load 0 of (Key (Triggering unit).) from fury_hash.)))
To clear hashtable:
  • Hashtable - Clear all child hashtables of child (Key (Triggering unit).) in fury_hash.
 
Status
Not open for further replies.
Top