• 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.

[vJASS] What are keys?

Status
Not open for further replies.
Level 15
Joined
Aug 7, 2013
Messages
1,338
Hi,

From Vexorian's manual:

key is a special vJass type that is meant to generate unique integer constants you can use in various ways, it is mostly intended to be used for key generation for warcraft 3's hashtable handle type.

What are these used for, exactly?
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
Must be for parent keys and child keys. I know my answer is stupid, so don't get mad lol.
 
Better don't use them. You can avoid it and it may result in weird bugs and you don't know where it comes from if you don't use it correctly.

For example in game you use certain parent keys that are not key generated, and you also use key for a static parent key, then they can come in confilct and you might not recignize it until a weird bug occurs in game.
 
Level 15
Joined
Aug 7, 2013
Messages
1,338
Alright but what would you use with a unique integer constant whose exact value you don't know beforehand?

I'm not a math / clever number kind of guy.
 
It is used for hashtables. There isn't much use besides that. It is convenient for sharing a hashtable across multiple triggers.

In an essence, it kind of serves a similar function as the resource Table. It doesn't offer the awesome syntax that Table has, but it serves as a unique ID (often a parent ID) so that you won't collide keys with other libraries/triggers.

If you use hashtables often, you'll find yourself occasionally using it as a simple dictionary (key -> value). In those cases, the parent ID can be selected arbitrarily, but you want it to be unique so that you won't collide with other triggers.

Now, just because you use a key, doesn't mean it can't conflict with other code. But the rule is: a key will be unique and different from any other key. Therefore, as long as you use keys for all your dictionary needs, you won't collide.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
It generates a unique integer which is computed and in-lined at compile time (no run time overhead). This is intended for use with hashtables so that you can assign certain types of data a unique index on another kind of data (no collision errors). In GUI people often use the hash of a string for this but this is not in-lined and computed at run time as well as is not collision free (the chances of collision are very low but not impossible and could result in strange errors).
 
Status
Not open for further replies.
Top