I just want to learn how this Hastable function works. All the variables, handles, saving/loading confuses me.
Defskull's post does exactly this I believe?
Yeah, it may be long and terrifying, but what else do you want?
The best way to learn stuff is to experiment. Go ahead and open the editor, try messing with the hashtables, see what it does.
Most of the time, you can just look at them as variables with a 2D (2-dimensional) array.
If you understand how variables with an array work, then you'll surely understand hashtables too.
After all, Var[0] and Var[0][0] do look alike
(
I thought that maybe I could use Hastable to store a unit temporary, like [...]
No.
Well, yes. You can. But it's not good.
Hashtables are slow. Don't use hashtables for something you can use a regular variable for.
Besides, I always have "Temp"-variables in my map: no need to create new variables for those things you've mentioned.
Hashtables shine when their large 2D-arrays are put to the test (the array index can go up to 2
31-1 I believe, in comparison to the lousy 2
13-1 for regular arrays).
This is extremely useful for Raw/Handle Id's: those values are usually a lot higher than the 8191-limit for regular arrays.
So with these hashtables, you can store any value
directly for a unit (that is: the value is directly linked with the ID of the unit). That's an O(1) lookup complexity.
Making them save some value that doesn't even really need those arrays is a waste of time.
I also don't understand these parentKey/childKey functions someone mentioned.
It's a bit like Folders on your PC: the folders are the parents, whereas the files are the children. If you delete the folder, then all files inside it will be gone.
Same rules apply here: something you want to save is always saved inside a file (child), this file is always saved inside a folder (parent).
The parent contains all the children, so if the parent is removed, all children inside it will be removed as well.
In GUI, the child comes first and then the parent.
Here's an example:
-
Hashtable - Save Handle of MyUnit as 0 of 1 in Hashtable
-
Hashtable - Save True as 1 of 1 in Hashtable
-
Hashtable - Save 16 as 2 of 1 in Hashtable
-
Hashtable - Save 3.14 as 1 of 0 in Hashtable
You store "MyUnit", "True" and "16" in Parent 1, but they're all saved in different children.
"3.14" is saved in a different Parent (0).
Now if you use "Clear Child Hashtable" and clear all children of the parent 1, then "MyUnit", "True" and "16" will all be removed from the hashtable.
"3.14" will still exist, because it has a different parent (0).
I really can't explain it any more basic than that
.