Hashtables (GUI)

tooltiperror

Super Moderator
Reaction score
231
What is a hashtable, you might ask? Let's ask our good and always reliable friend, wikipedia.
In computer science, a hash table or hash map is a data structure that uses a hash function to map identifying values, known as keys, (e.g., a person's name) to their associated values (e.g., their telephone number). The hash function is used to transform the key into the index (the hash) of an array element (the slot or bucket) where the corresponding value is to be sought.

That is quite a complicated, and technical way of describing what a hashtable is. Perhaps a picture should help.

scgh2d.png

[size=-8](tinypic killed the side, ignore it.)[/size]​

It is a normal X,Y grid. Now, imagine that you could put a unit, or a destructible, or a doodad, or whatever you want in each box. The box you choose on the X axis is called the key, or the identifier. The box you choose on the Y axis is called the index.

Unknown to you, everything in the game that is physically there, like the weather or units or anything like that is called a [LJASS]handle[/LJASS]. These handles are a type of variable. A lot of other variable types (such as units) are just types of handles. Every handle is given a number when it is created. Let's say for example you create a footman, it may get the number 12,774. This number is called the Handle ID. You can use this with a hashtable to do some pretty funky things.

In GUI, you are given a series of functions named pretty similarly. Here's some examples of them.

  • Hashtable - Save Real
  • Hashtable - Save Integer
  • Hashtable - Save Boolean
  • Hashtable - Save String
  • Hashtable - Save Unit Handle

All of them look pretty much like this.

Trigger:
  • Hashtable - Save Value as Value of Value in (Last created hashtable)


Fun fact, this will get you ready for JASS. These things you fill in, when you use GUI, these are called Arguments. And, in this case, you have four of these 'arguments'. The first value, the second, the third, and a hashtable. The second value is the one we really want to focus on. It is the box in the X axis, the key. Of course, an actual hashtable goes on forever with it's numbers. And you know how I mentioned that we have those nifty numbers each handle, like a unit, right? We can set that second value to the Handle ID of the unit you want to store data for. Let's say a handy dandy footman. Let's use Hashtable - Save String.

Trigger:
  • Hashtable - Save <Empty String> as (Key (Triggering unit)) of 0 in hashtable


The function Key() gets the Handle ID of the unit for us. Let's say our footman's ID is 12774 (farmiliar, right?) This fills in the twelve-thousand seven hundred and seventy-fourth box on the right and zero up with "" (because it's an empty string). Let's try something different, let's save it as the name of our footman, Sir Vincent.

Trigger:
  • Hashtable - Save Sir Vincent as (Key (Triggering unit)) of 0 in hashtable


There we go, it's filled up. Now you may be asking yourself, "Why do I give a damn about this?" And there is actually a very good reason for this. Let's say we have a jewel that only Sir Vincent can pick up. We can do that quickly with our hashtable.

Trigger:
  • hashtable
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to The Vincent Family Jewels
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Load (Key (Triggering unit)) of 0 from hashtable) Equal to Sir Vincent
        • Then - Actions
          • Do nothing
        • Else - Actions
          • Unit - Order (Triggering unit) to drop (Item being manipulated) at (Position of (Triggering unit))


It leaks a position, but you get the idea of the hashtable can then be used, and how you are 'loading' the value back. Now, let's get onto a more serious issue that hashtables actually solve: Making spells MUI. Here we have a spell that will create a special effect, set it to a variable, and then destroy it after a wait. Normally, this is not MUI, because the variable could be reset during the wait. However, because the Triggering Unit always remains the same, we can just use the Triggering Unit's Handle ID. Hashtables have (seemingly) unlimited data storage, so you can save as much stuff about a spell in the hashtable as you want. Instead of using 0 as our index, we'll use the Execution Count of the current trigger which will be unique each time the trigger runs. When you want a lot of things in your trigger and you're only using one hashtable, simply use arrays and base everything off of the execution count.

Trigger:
  • hashtable
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Thunder Clap
    • Actions
      • Special Effect - Create a special effect at (Center of (Playable map area)) using Abilities\Spells\Human\ThunderClap\ThunderClapCaster.mdl
      • Hashtable - Save Handle Of(Last created special effect) as (Key (Triggering unit)) of Execution count of (This trigger) in hashtable
      • Custom script: call PolledWait(5.00)
      • Special Effect - Destroy (Load (Key (Triggering unit)) of Execution count of (This trigger) in hashtable)


Now, even if another unit casts the spell during the five seconds, it will still be MUI because of Triggering Unit. You can use this with any spell, or any system in your map, or for whatever data storage you want.

But, there's a teeny-tiny bit more you need to know about hashtables I didn't mention above, and this seemed like the best place to mention it. In order to use a hashtable, you need to create it first (duh). Here's the easy way to do it, with a function and a variable set.

Trigger:
  • hashtable
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set hashtable = (Last created hashtable)


Some other things you may need to know:
  • You can only have 256 Hashtables at a time.
  • A hashtable is fast.
  • Unfortunately, you can not use hashtables to store data between maps.

You have been enlightened on the way of the hashtable.
p.s. lime
 

Jedi

New Member
Reaction score
63
Trigger:
  • * hashtable
    • o Events
      • Unit - A unit Starts the effect of an ability
    • o Conditions
      • (Ability being cast) Equal to Thunder Clap
    • o Actions
      • Special Effect - Create a special effect at (Center of (Playable map area)) using Abilities\Spells\Human\ThunderClap\ThunderClapCaster.mdl
      • Hashtable - Save Handle Of(Last created special effect) as (Key (Triggering unit)) of 0 in hashtable
      • Custom script: call PolledWait(5.00)
      • Special Effect - Destroy (Load (Key (Triggering unit)) of 0 in hashtable)


You can use Wait game time instead of PolledWait with a jass line.

This is not MUI, if same unit casts this spell again, first effect won't get destroyed.Because you are storing another effect inside of triggering unit's key again.
 

tooltiperror

Super Moderator
Reaction score
231
Fine, I can change it to use the trigger execution number.

edit: done, now correctly MUI.
 

TomTTT

New Member
Reaction score
44
Why is this in Graveyard?
I found this tutorial a VERY useful tutorial and now i do understand what hashtables are for and how to use them. This isn't worst than any other guide on hashtables. :thup: +rep
 

skyblader

You're living only because it's illegal killing.
Reaction score
159
Probably because it's old. Graveyard doesn't mean it's not approved.
 

Accname

2D-Graphics enthusiast
Reaction score
1,463
Probably because it's old. Graveyard doesn't mean it's not approved.

1). this isnt old

2). what you said isnt true

pm a moderator if you believe the graveyarding of this thread is a mistake. he might tell you most probably. darthfett is a moderator for this forum i think.
 

skyblader

You're living only because it's illegal killing.
Reaction score
159
1) It's 2 months plus... Not very old.. But still.

2) If you're talking bout "graveyard doesn't mean not approved" is not true, then explain my resource going to graveyard, after being approved, but not updated for a year plus. And now after updating it, it was moved out of graveyard.
 

Accname

2D-Graphics enthusiast
Reaction score
1,463
a turtorial or system is not graveyarded if the moderators think they are useful and properly made. there are for example threads like these:
this
or
this.
and probably many more which are old and not updated for years but still not graveyarded.

if this is graveyarded the moderators do not approve of it.
but considering no moderator left a response saying why this is graveyarded nor telling the author via PM it might be a mistake.
 

skyblader

You're living only because it's illegal killing.
Reaction score
159
Well... What I said about being in graveyard doesn't mean it's not approved is still true.

"Old, unapproved submissions that didn't receive any updates in a long time will end up here."

I'm not sure whether what you said is true... Because the examples you've shown me are good ones. Maybe very good in fact. Not stated specifically that only unapproved tutorials go into the graveyard, so I'm just saying there's a possibility because it's old.

Though tooltiperror should request for it to be moved back :p
 

baassee

Member
Reaction score
5
I wonder why this is graveyarded too.

Thought hashtable is like a 2D array if I remember correctly.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top