Hashtables (GUI)

tooltiperror

Super Moderator
Reaction score
233
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
 
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.
 
Fine, I can change it to use the trigger execution number.

edit: done, now correctly MUI.
 
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
 
Probably because it's old. Graveyard doesn't mean it's not approved.
 
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.
 
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.
 
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.
 
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
 
I wonder why this is graveyarded too.

Thought hashtable is like a 2D array if I remember correctly.
 
General chit-chat
Help Users
  • Varine Varine:
    A probate is usually done with a will, yes? If so I am sorry for your loss
    +1
  • The Helper The Helper:
    Yeah Tom, me too sorry for your loss buddy my mom told me she finds out her olds friend died from Google searching them. She had not talked to one of her old friends in a year and found out she died from Google. Also another one in the same session. RIP all of them my sincere condolences Tom
    +1
  • Varine Varine:
    We have some elderly guests that regularly come hang out at the bar at the end of the night, and every once in a while we don't see someone for a few weeks and then someone shows up with their obituary.
  • Varine Varine:
    We usually let them do their memorials there in the morning if they want to and I'll make them some snacks and drinks. There was one guy named Tom that came in like every night and would sit by himself and get a bunch of soup and a glass of wine. idk why but he LOVED our fucking soup, like he would order a fucking quart of it at a time and would always get so sad when we stop doing it for the summer.
    +1
  • Varine Varine:
    But he also loved our calamari, which is another thing I hate but it sells super well so I can't change it. There was one day he came in and was asking me how to make it, because he tried to at home once in the off season when we stop running it and he really wanted it lol
  • Varine Varine:
    I think he's one of the only people I've made recipes for for free because he really wanted a broccoli cheddar, and it was like dude I don't have a recipe, it's just whatever I have, but here, this is how you do it
  • Varine Varine:
    I don't think he ever figured out how to do the calamari in a pan though, like idk how to do that either. He was afraid of the at home deep fryers though and it's like yeah, that's fair, I am too
  • Varine Varine:
    He was just such a sweet old man, we had two servers pregnant and they held a baby shower together, he was soooooo fucking excited to get to see a baby. Unfortunately he died a month or so before they were born
  • The Helper The Helper:
    So I decided to Google some people that I had not seen or heard from in a while and sure enough one of my old best friends, we had a falling out years ago but whatever, find out he died of Pancreatic Cancer in January. I have also lost a few of my closer acquaintances from growing up the last year. Getting old - people die - I kinda thought it was going to be this way a few years ago....
    +2
  • The Helper The Helper:
    Forum running super slow again
  • Ghan Ghan:
    Not really clear from the stats as to what is causing the slowness.
  • Ghan Ghan:
    We get a lot of guest traffic so it may just be the load is getting too high and not from any particular source.
  • Ghan Ghan:
    Looks like the server is maxed out on CPU.
  • Ghan Ghan:
    Oh it looks like a lot of the traffic is Silkroad Forums. That domain isn't protected by Cloudflare.
  • Ghan Ghan:
    But the old Silkroad site is still on its own server. I just had a test site set up on this server for it.
  • Ghan Ghan:
    I just disabled that test site. Let's see if that helps the load.
  • Ghan Ghan:
    Looks much better already.
  • The Helper The Helper:
    I had actually forgot about the Silkroad site. I had asked
  • The Helper The Helper:
    SD Ryoko about it and he said the couple of people left on there really like it, that was a few years ago, maybe I should check back
  • jonas jonas:
    I guess when you're getting old, and the last day of soup season draws near, you start wondering
  • jonas jonas:
    will I make it to the start of the next season? or was this the last time I'll ever have my favorite dish?
  • The Helper The Helper:
    I am doing my first Vibe Coding project. In installed the environment and tools according to instructions but it is all chat doing this for me at my direction. It is fun really and holy shit I might finish in 2 hours what it would have taken a day to in my Access and this would be an electron app complete new
  • Ghan Ghan:
    Good stuff.
  • Ghan Ghan:
    Just make sure it is secure. :)
  • The Helper The Helper:
    It will only be on internal network

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials
      Top