• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

What does the hashtables do?

Status
Not open for further replies.

TKF

TKF

Level 19
Joined
Nov 29, 2006
Messages
1,267
The hashtables was added in the 1.24 patch. It's a new thing for me and I don't know what it really does.


But what does it do and what is it good for? In which situation is it useful to use?




Rep+ for the best explanation and answers.
 
Level 3
Joined
Jul 15, 2009
Messages
42
I think its like a saving and loading trigger as what ive seen since most of it says that
 
Level 11
Joined
May 11, 2008
Messages
830
The best way to describe Harshtables?

Glue, that's it. You place 2 interger or whatever at start so when it's loaded, you load the harshtable, say I need a 3rd ressource by mining oil or whatever, you create 1 harshtable for the ability and the other for the region it enters. You stick both of them together to make 1 trigger work.
 
Level 10
Joined
Aug 19, 2008
Messages
491
They save anything under 2 integers. Like, if you save Footman under 1 and 2, you can load it by typing Load Unit 1 and 2 or whatever the GUI command is.
It's like a two dimensional array.

If you're a GUI user I'd say that you should use them. Sure, everything has disadvantages but comparing hashtable's to the disadvantages of other GUI things, they're nothing.
(Short said no, there are none)
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,285
Hashtables store values and act like a 2D array as far as you interface with them. Further more their indexes have no bounds and can take any integer (32 bit two's compliment). As far as you the user goes, this is all you need to know.

They actually work by what their name says, they use hash related systems. This however is purly for explaining how they store data so efficently so really is not needed to use them.
 
Level 12
Joined
Aug 7, 2004
Messages
875
Sry I'm not skilled using triggers. I don't know what I'm need them for?.... I don't get a grasp of it's usufulness...


I kinda using integers and reals covering mostly everything....

What you need it for?

Instead of creating variables to store what unit a Footman is attacking, hashtable allows you to store that attacked unit to a table that you initialized and created beforehand.

Lets say Bob attacks Ralle.

I want Bob to have an integer ID of lets say 1.

I also want any attacked unit to be represented as 2.

So I save Ralle to a table with a parent key 1 and a child key 2.

Now, I wan't to refer to Ralle because I wan't him to be turned into a sheep everytime bob attacks. So instead of creating a global variable for Ralle, all I have to do is simply Load a unit from the table with parent key 1 and 2.

Walah!

To be more efficient, use

GetHandleId() to take the integer representation of any Object instead of assigning them random integers...

Also use StringHash if you want to convert a string to an integer. This helps to identify the child key using a string instead of an integer. Lets say instead of putting 2 for child key, you put "attacked unit" and converted it to an integer using StringHash.
 
  • Like
Reactions: TKF
Level 12
Joined
Aug 7, 2004
Messages
875
Um, too vague and interpreted to be an incorrect explinantion.

Hahstables can store and retreve values like a limatless 2D array, once the games ends their contence is lost permantly.

What I don't get is this...

Karune said:
All handle types share the same key namespace. For instance, if you call SavePlayerHandle followed by SaveUnitHandle, with the same keys, then the unit handle will overwrite the player handle. Even though the handle functions share the same key space, The SaveXHandle and LoadXHandle functions are type safe. For instance, calling SavePlayerHandle followed by local unit u = LoadUnitHandle will result with u initialized to null.
Source:http://forums.battle.net/thread.html?topicId=17730193178

Can you explain?
 
Level 11
Joined
Feb 22, 2006
Messages
752
If you use the same hashtable:

JASS:
function foo takes unit u, player p returns nothing
    local hashtable t = InitHashtable()
    local unit u
    local player p
    call SaveUnitHandle(t, 1, 1, u)
    call SavePlayerHandle(t, 1, 1, p) // using the same keys (1, 1) here overwrites the saved unit from the previous line even though we are now saving a player instead of another unit. This will also be true for ALL handle types, so if I used the same keys and saved a special effect, the unit still gets overwritten.
    set u = LoadUnitHandle(t, 1, 1) // u is set to null because the saved unit was overwritten
    set p = LoadPlayerHandle(t, 1, 1) // works correctly
endfunction
 
Level 12
Joined
Aug 7, 2004
Messages
875
If you use the same hashtable:

JASS:
function foo takes unit u, player p returns nothing
    local hashtable t = InitHashtable()
    local unit u
    local player p
    call SaveUnitHandle(t, 1, 1, u)
    call SavePlayerHandle(t, 1, 1, p) // using the same keys (1, 1) here overwrites the saved unit from the previous line even though we are now saving a player instead of another unit. This will also be true for ALL handle types, so if I used the same keys and saved a special effect, the unit still gets overwritten.
    set u = LoadUnitHandle(t, 1, 1) // u is set to null because the saved unit was overwritten
    set p = LoadPlayerHandle(t, 1, 1) // works correctly
endfunction

Ic, thanks!
 
Status
Not open for further replies.
Top