Hashtables and MUI

Level 13
Joined
Sep 28, 2011
Messages
942
But the no limit argument is not good: if there is more that 8192 abilities acting in same time it will lag so much that no one will use the map. use dynamic indexing with arays it is so fast and have so much possibilities.Because of this tutorial hive spell section will be spammed with hash table spells who are slow and buggy.(The first time I have seen a hash table using spells it had problems with allocating and unallocating).Only some legendary complex systems can merit hashtable.
 
Level 19
Joined
Aug 13, 2013
Messages
1,679
But the no limit argument is not good: if there is more that 8192 abilities acting in same time it will lag so much that no one will use the map. use dynamic indexing with arays it is so fast and have so much possibilities.Because of this tutorial hive spell section will be spammed with hash table spells who are slow and buggy.(The first time I have seen a hash table using spells it had problems with allocating and unallocating).Only some legendary complex systems can merit hashtable.

IT DEPENDS FROM THE USER AND THE KIND OF SPELL.
Dynamic Indexing, Indexed Arrays, Hashtables, they all have Pros and Cons.
 
Level 29
Joined
Oct 24, 2012
Messages
6,545
But the no limit argument is not good: if there is more that 8192 abilities acting in same time it will lag so much that no one will use the map. use dynamic indexing with arays it is so fast and have so much possibilities.Because of this tutorial hive spell section will be spammed with hash table spells who are slow and buggy.(The first time I have seen a hash table using spells it had problems with allocating and unallocating).Only some legendary complex systems can merit hashtable.

While i do not like hashtables for most of the reasons you do dynamic indexing is not the way to go. As shown by Maker in a thread that lasted a while dynamic indexing is flawed. It is better to use indexed arrays or unit group with unit indexer to do the work.
 
Level 8
Joined
Apr 13, 2008
Messages
183
Yes following line does leak a location:

  • Unit - Move (Picked unit) instantly to ((Position of (Picked unit)) offset by KnockbackDistance towards KnockbackAngle degrees)

So i have to create location handle and reference that and destroy it at the end okay...

and if i make a destructible group to clear off the trees so the units do not get stuck inside how do i destroy the destructible group?
 
So i have to create location handle
a location handle will be created at that point you call (Position of Unit) or what ever. And the variable is your reference that points to it.

and destroy it at the end okay
Yes.

how do i destroy the destructible group?
There exists nothing like a destructible group. It is a plain enumeration with no extra handle created.

If you have more questions please post in the respective sections, instead that we use this thread for general questions like memoy leaks.
Or in memory leaks threads, or Triggers&Scripts, or WorldEditorHelpZone. What fits best. :)
 
Last edited:
Level 1
Joined
Apr 7, 2017
Messages
1
Hey guys, eight years late on the hash table train.

Is it possible to pass units as values, or are they only used as keys?

For example, I'm making a map with a squad system. Each squad has a leader that is selected randomly from the ranks of the squad when the current leader dies. I was thinking of having a hash table to keep track of each player's current squad leaders.

Can I do something like this:

Hash table - Save (squad leader unit) as (custom value of unit) of (player number of owner of unit) in squadLeaderTable;

Does this make sense? Like the first squad player one makes will have its leader stored in 0 of 1 in the squadLeaderTable table. Is this OK? The custom value increments every time a new squad is made; every squad of a player has a unique custom value.
 
Level 7
Joined
Apr 18, 2010
Messages
102
I have an idea how to make a SUI spell using hashtables without using dynamic indexing.. WHY not just create a dummy and use its keys?

Let say the healing spell

On cast
Create a dummy
Save the caster as X integer of key of the dummy unit in hashtable x

That way even if the the same unit casts the healing spell multiple times, he would always be creating a dummy unit tht would serve as the instance of the spell
 
That is the approach in the tutorial but worse.
It's literary the same method but more complicated in practice
Not really, because solely using the caster or target as key makes it not possible to allow multiple instances, as instances would get overwritten.
That way even if the the same unit casts the healing spell multiple times
 
Level 22
Joined
Sep 24, 2005
Messages
4,823
It's not a random key but a set of keys ( [1-instanceCount] ) that grow dynamically. Also, why would you need to loop through it, you just need to pop or push things from the index stack if I remember correctly...
 
Level 22
Joined
Sep 24, 2005
Messages
4,823
1. It's not random, it's just unsorted. The last pushed index will be the first to be popped (LIFO?).
2. You pop it; The last pushed index will be the first index to be popped out. Are you talking about random access? You won't be using a list for that if that's the case.

EDIT: Ah, I looked at the threads topic, it's a GUI tutorial, disregard what I said, I thought it was about constructors or something.
 
Last edited:
Level 3
Joined
Jun 9, 2019
Messages
27
Sorry I ask this maybe i havent read it well but I steal dont know what is the use of it it is just a variable which use 1name +2 integer instead of a name am I right?pls some 1 answer this noob question
And a example wich the variable dont work and the only way be the hastable sorry if I am 1000%wrong and underestod none of this tutorial
 
Level 2
Joined
Dec 19, 2019
Messages
11
That's a nice and fine tutorial! I haven't been using the Wc3 Editor for over a decade and after reading that guide HashTables are just a charm! The only thing I had to spend second things on was how the key was utilized at first but the method where you saved it as a string value made it pretty clear then!

Sorry I ask this maybe i havent read it well but I steal dont know what is the use of it it is just a variable which use 1name +2 integer instead of a name am I right?pls some 1 answer this noob question
And a example wich the variable dont work and the only way be the hastable sorry if I am 1000%wrong and underestod none of this tutorial

I'll try to answer your question. There are most of time more than one way how to do things and a HashTable helps you sliming down quiet a lot and allow you to easier access and manipulate values and instead of using 4-10 different variables to store things you can use one HashTable for it which potentially makes everything faster, because you do not load all these different variables into your RAM what may results in having a faster map [I am not 100% sure how the Wc3 Engine is handling things so please correct me if I am wrong on this statement]. It comes in handy when you want to save more values on a certain "thing".

Let's say we have a Map with a circle and a Trigger is spawning 3-5 units every 5 seconds at the exact same spot and it shall be owned by the same player. The catch is, every even unit shall run clockwise and every uneven unit counter clockwise for 10 rounds. After it finished running 10 rounds it shall just disappear.

So let's assume you want to fulfil these requirements with an Array that holds all the units. Then you would need another Array to check if they are an even spawn and another one to keep count of them and further than that, you would also have to provide some intelligence which keeps your UnitArray from growing to infinity which would make it really big.

For one thing you could use the custom value function but in this place a HashTable is your Swiss army knife for that.
  • Actions
    • Unit Group - Pick every unit in (Units owned by Player 12 (Brown).) and do (Actions)
      • Loop - Actions
        • Hashtable - Save true as (Key clockwiseMovement.) of (Key (Picked unit).) in unitAI.
        • Hashtable - Save 0 as (Key roundCounter.) of (Key (Picked unit).) in unitAI.
And that's the point where you can save many more things to it. You could also save the next region they shall run, etc.
The big advantage is, that you can easily pick your values directly from that unit and that basically works for everything.
Another example would be if you do that for spells. Just take a look at the example of the knockback units. If you do it exactly as the TE did it, it is 1.) insanely slim and sharp and 2.) every player can use that ability the same way without any of the variables overwriting themselves.

It may sound a little complex at first but as long as you are doing all your Triggers with the GUI this will elevate your triggering!
 
Level 9
Joined
Mar 17, 2016
Messages
133
Would this not leak?

  • empty.gif
    empty.gif
    empty.gif
    empty.gif
    line.gif
    join.gif
    comment.gif
    -------- Move the unit and update time remaining --------
  • empty.gif
    empty.gif
    empty.gif
    empty.gif
    line.gif
    join.gif
    unit.gif
    Unit - Move (Picked unit) instantly to ((Position of (Picked unit)) offset by KnockbackDistance towards KnockbackAngle degrees)
  • empty.gif
    empty.gif
    empty.gif
    empty.gif
    line.gif
    joinbottom.gif
    set.gif
    Hashtable - Save (RemainingTime - 0.04) as 2 of (Key (Picked unit)) in knockbackTable
[hidden/]
 
Level 19
Joined
Aug 13, 2013
Messages
1,679
^
As a final note, these triggers are merely examples. As you may or may have not noticed, the knockback trigger would require memory leak fixing since it leaks 25 locations each second for every unit that is being knocked backward. I intentionally left the triggers how they are so they would be easier to understand. Those who wish to use these kinds of triggers in their maps should make sure to fix any memory leaks that were not cleaned up in the examples.
 
Level 2
Joined
Aug 22, 2020
Messages
18
Not sure if I should post this here or in the WE Triggers Help Section, but here we go :psmile:

On Map Initialization event, I would like to create a random unit.
That unit might be 3 different types of wolves (with equal chance to spawn) and depending on what the unit is, it would drop different item.

How can I use hashtable (I suppose it's the right tool for this) for such effect?

I have read the tutorial, but I'm still a bit lost in it, so if anyone can make a practical example how to do this, I would be grateful!
 

Uncle

Warcraft Moderator
Level 42
Joined
Aug 10, 2018
Messages
4,181
Not sure if I should post this here or in the WE Triggers Help Section, but here we go :psmile:

On Map Initialization event, I would like to create a random unit.
That unit might be 3 different types of wolves (with equal chance to spawn) and depending on what the unit is, it would drop different item.

How can I use hashtable (I suppose it's the right tool for this) for such effect?

I have read the tutorial, but I'm still a bit lost in it, so if anyone can make a practical example how to do this, I would be grateful!
You can PM me if you'd like, I can help you out. Inbox -> Start a New Conversation.
 
Last edited:
Level 13
Joined
Jun 2, 2009
Messages
709
My English is not good, downloaded map and still i don't understand what is this. Dear Uncle told me about this system in here. He told me i need this system for my AI system. Is someone can tell me what is this? I am a low IQ person, so try to be a simple please.

 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,176
That's the point of the tutorial, you're not supposed to just download the map and reverse engineer it.
If this tutorial is difficult, you can read an alternative. If those are confusing as well, maybe you should learn more basic coding/GUI/triggering first.

edit:
You could also look up tutorials for HashMaps in a language like Java on youtube, the syntax is a bit different but the idea is the same. Although this is only an option if you don't use GUI most likely.
 
Level 13
Joined
Jun 2, 2009
Messages
709
That's the point of the tutorial, you're not supposed to just download the map and reverse engineer it.
If this tutorial is difficult, you can read an alternative. If those are confusing as well, maybe you should learn more basic coding/GUI/triggering first.

edit:
You could also look up tutorials for HashMaps in a language like Java on youtube, the syntax is a bit different but the idea is the same. Although this is only an option if you don't use GUI most likely.
The funny part is i have a 20 years old map + since 2002 i have created many maps that i can't count. But there are few things i never understand. This is why i can call myself as "idiot" easily. Have you checked my topic? Uncle says it is essential to me. But i need another solution.
 
Level 20
Joined
Nov 18, 2012
Messages
1,612
If you'd read the tutorial, you wouldn't have asked "what is this" in the first place. Like Chaosy said, you're not supposed to just open the map and study the triggers as if it's the end of the world. You're supposed to read the tutorial, understand the steps, do the steps yourself, test it yourself. You're not stupid, you're just stubborn regarding the willing to get your head up to work on a subject that is challenging.

If you've read the tutorial, what is it that you don't understand exactly? What section? Part? Text? This would be more productive if you were more specific.
 
Level 13
Joined
Jun 2, 2009
Messages
709
If you'd read the tutorial, you wouldn't have asked "what is this" in the first place. Like Chaosy said, you're not supposed to just open the map and study the triggers as if it's the end of the world. You're supposed to read the tutorial, understand the steps, do the steps yourself, test it yourself. You're not stupid, you're just stubborn regarding the willing to get your head up to work on a subject that is challenging.

If you've read the tutorial, what is it that you don't understand exactly? What section? Part? Text? This would be more productive if you were more specific.
I disagree. You are not stupid and you will never understand what i feel.

"For starters, it's a data structure capable of holding almost any kind of data in Wc3. It can hold integers, unit, special effects, and anything else you would ever need to store."

The variables doing the same thing. This is why i don't understand why should i need it. This why i have downloaded and tried to learn it.
 
Level 20
Joined
Nov 18, 2012
Messages
1,612
I disagree. You are not stupid and you will never understand what i feel.

"For starters, it's a data structure capable of holding almost any kind of data in Wc3. It can hold integers, unit, special effects, and anything else you would ever need to store."

The variables doing the same thing. This is why i don't understand why should i need it. This why i have downloaded and tried to learn it.
Hashtables are like essencially variable arrays, while having "more functionality". You have an array variable x[1], this is index 1, you can also have index 2, x[2].
Hashtables are 2D arrays, so it would be hashtable[x][y]. Just like a table, imagine one in microsoft word. Furthermore, it allows to store handle ids. Handles are everything except reals, integers, booleans, strings. So they would be for example units, items. Ids means that it's a unique identifier to the object (handle) in the form on an integer value.
You could have something similar to hashtable[(Get triggering Unit)][1] hashtable[(Get triggering Unit)][2] hashtable[(Get triggering Unit)][3].
Variable arrays and hashtables have some common ground, but hashtables have functionality that simply normal variable arrays don't have.
No one would ever understand what hashtables would be for just from reading the first introductory sentences, they're simply there to say something general. It's impossible to describe it like that.
 
Level 13
Joined
Jun 2, 2009
Messages
709
Then is there any way to make this trigger (check uncle's post) with variables? I will create many variables for this. At least i know how to use Variable.s

 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,176
You can use dynamic indexing instead.
Which is arguably more difficult to understand but it technically uses normal variables.

 
Top