Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
I'm sorry if its seems an obvious or dumb question but i'm a noob to map editting and i don't know what Hashtable does ? If anyone knows please explain !
Hmh, you can look at it as a variable, yes.
Are you familiar with arrays?
Because one way one can look at a hashtable, is as a 2D-array.
This means that where a regular array would be something like:
"Hero[1]" (the hero for player 1)a 2D-array would be:
"Hero[1][1]" (the first hero for player 1, where:
"Hero[1][2]" would be the second hero for player 1).
If you understood that, then you're halfway through understanding a hashtable.
However: just a 2D-array isn't enough to justify a hashtable (because a 2D-array can be created with a single array with a little math).
What's so brilliant about a hashtable, is that each array can have up to '231 - 1' slots.
A regular array can only contain 8192 slots (a couple billion less).
So what's the use of 2 billion slots (might even be 4 billion if you count negative integers)?
Well, for one: each object you place on the map has a specific ID (no other object on the map can ever have that same ID).
This ID is usually a very large number (way larger than 8192, which means it's too big for a regular array).
With hashtables, we can do something like this:
"Variable[UNIT_ID][0] = 42"This will save the value 42 for the unit with id UNIT_ID. It saves a value for a specific object.
For making things MUI, being able to save things for a specific object is an amazing convenience.
Further reading.


We're not storing the ID. We're using it in the array.Why would we need to store the ID of each and every single object in the map?
Not quite sure what you mean here.Its ID is greater than 8192, not its size, because it would only count as 1 object ? right ?
Ok, i think i got it a little, but its still confusing.
It'd be nice if someone can give an example or two of a trigger using hashtables for a purpose. Because i'm confused how or why the hastables would be used !
Trigger 1

Events


Unit - A unit enters (Playable map area)

Conditions

Actions


Set UnitVar = (Triggering unit)


Custom script: set udg_Id = GetHandleId(udg_UnitVar)


-------- Variable 1: Level --------


Set Level = 1


Hashtable - Save Level as 0 of Id in Hash


-------- Saved LEVEL(1) in DataSlot ZERO(0) in the Unit (Id) in the HASHTABLE --------


-------- Variable 2: Experience --------


Set Exp = 0


Hashtable - Save Exp as 1 of Id in Hash


-------- Saved Experience(0) in DataSlot ONE(1) in the Unit (Id) in the HASHTABLE --------


-------- Variable 3: Required Experience --------


Set ReqExp = (Level x 100)


Hashtable - Save ReqExp as 2 of Id in Hash


-------- Saved ReqExperience(Exp*100) in DataSlot TWO(2) in the Unit (Id) in the HASHTABLE --------
Trigger 2

Events


Unit - A unit Dies

Conditions

Actions


Custom script: set bj_wantDestroyGroup = true


Set UnitVar = (Triggering unit)


Set PointVar = (Position of UnitVar)


Set GroupVar = (Units within 600.00 of PointVar)


Set ExpGained = (20 / (Number of units in GroupVar))


Unit Group - Pick every unit in GroupVar and do (Actions)



Loop - Actions




Set UnitVar = (Picked unit)




Custom script: set udg_Id = GetHandleId(udg_UnitVar)




-------- Variable 1: Level --------




Set Level = (Load 1 of Id from Hash)




-------- Variable 2: Experience --------




Set Exp = ((Load 2 of Id from Hash) + ExpGained)




Hashtable - Save Exp as 1 of Id in Hash




If (All Conditions are True) then do (Then Actions) else do (Else Actions)





If - Conditions






Exp Greater than or equal to ReqExp





Then - Actions






-------- Variable 1: Level --------






Set Level = ((Load 1 of Id from Hash) + 1)






Hashtable - Save Level as 0 of Id in Hash






-------- Variable 3: Required Experience --------






Set ReqExp = (Level x 100)






Hashtable - Save ReqExp as 2 of Id in Hash





Else - Actions


Custom script: call RemoveLocation(udg_PointVar)


Custom script: call DestroyGroup(udg_GroupVar)
Hashtable - Save A as B of C in D
call SaveInteger(D, C, B, A)
@Spartipilo : Thanks a billion. I get it now. That was a great example ! REP+
@Hell Master : Thanks for that guide, its also good, but if i continue to read it all, i would forget what i just learnt.
I think i would mess up with the Hastables and experiment with them, and learn about it from that !
Anyways Thanks all !

