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,462
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,462
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.
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/
  • The Helper The Helper:
    Decided to put up a healthier type recipe to mix it up - Honey Garlic Shrimp Stir-Fry https://www.thehelper.net/threads/recipe-honey-garlic-shrimp-stir-fry.193595/

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top