System Hashtable Attachment System (Local Handle Vars with hashtables)

jwallstone

New Member
Reaction score
33
Hashtable Handle Attachment System (Local Handle Vars with hashtables)

Here's a rewrite of KaTTaNa's Local Handle Vars using hashtable natives. The original can be found here:
http://www.wc3jass.com/viewtopic.php?p=3737

NOTE: I claim absolutely no credit for this. This involved very little work on my part, and definitely no creative work. All credit should go to KaTTaNa. I'm posting this only to help out other people who may be interested in an updated version for patch 1.24.

The system can be used to "attach" or "associate" any of the core data types (integers, reals, strings, booleans) as well as handles of the agent type with any other handle. (Agent type handles are the reference counted handle types.)

There are two ways to use this:
1. Easy way - create a Hashtable global var, and replace the return value in the HATable function with your variable
2. Less easy, but better way - create a Hashtable global var and replace all function calls to HATable() with your global variable. The function HATable can be removed.
Either way, the hashtable must be initialized with a call to InitHA() before use.

Notes:
1. The function for saving handles has been renamed to SetHandleAgent, to reflect the fact that only agent type handles can be saved.
2. To erase an entry, you do not simply save a 0, false, or null value. Instead call the appropriate "Remove_blank_" function. This is to allow these values to be saved as legitimate entries, and to ensure the proper operation of HaveSaved_blank_ when these values are saved. Furthermore, it enforces better code writing in terms of readability and clarity of function use.
3. The Remove functions have an extra step of storing a useless value (0,null,false) to prevent bugs that were discovered with hashtables as of the beta patch 1.24. If the bugs no longer exist, those lines will be removed.

JASS:
function HATable takes nothing returns hashtable
    return udg_HATable
endfunction
function InitHA takes nothing returns nothing
    local hashtable ha = HATable()
    set ha = InitHashtable()
    set ha = null
endfunction

function SetHandleAgent takes handle subject, string name, agent value returns nothing
    call SaveAgentHandle(HATable(), GetHandleId(subject), StringHash(name), value)
endfunction
function SetHandleInt takes handle subject, string name, integer value returns nothing
    call SaveInteger(HATable(), GetHandleId(subject), StringHash(name), value)
endfunction
function SetHandleBoolean takes handle subject, string name, boolean value returns nothing
    call SaveBoolean(HATable(), GetHandleId(subject), StringHash(name), value)
endfunction
function SetHandleReal takes handle subject, string name, real value returns nothing
    call SaveReal(HATable(), GetHandleId(subject), StringHash(name), value)
endfunction
function SetHandleString takes handle subject, string name, string value returns nothing
    call SaveStr(HATable(), GetHandleId(subject), StringHash(name), value)
endfunction

function GetHandleInt takes handle subject, string name returns integer
    return LoadInteger(HATable(), GetHandleId(subject), StringHash(name))
endfunction
function GetHandleBoolean takes handle subject, string name returns boolean
    return LoadBoolean(HATable(), GetHandleId(subject), StringHash(name))
endfunction
function GetHandleReal takes handle subject, string name returns real
    return LoadReal(HATable(), GetHandleId(subject), StringHash(name))
endfunction
function GetHandleString takes handle subject, string name returns string
    return LoadStr(HATable(), GetHandleId(subject), StringHash(name))
endfunction
function GetHandleUnit takes handle subject, string name returns unit
    return LoadUnitHandle(HATable(), GetHandleId(subject), StringHash(name))
endfunction
function GetHandleItem takes handle subject, string name returns item
    return LoadItemHandle(HATable(), GetHandleId(subject), StringHash(name))
endfunction
function GetHandleTimer takes handle subject, string name returns timer
    return LoadTimerHandle(HATable(), GetHandleId(subject), StringHash(name))
endfunction
function GetHandleTrigger takes handle subject, string name returns trigger
    return LoadTriggerHandle(HATable(), GetHandleId(subject), StringHash(name))
endfunction
function GetHandleEffect takes handle subject, string name returns effect
    return LoadEffectHandle(HATable(), GetHandleId(subject), StringHash(name))
endfunction
function GetHandleGroup takes handle subject, string name returns group
    return LoadGroupHandle(HATable(), GetHandleId(subject), StringHash(name))
endfunction
function GetHandleLightning takes handle subject, string name returns lightning
    return LoadLightningHandle(HATable(), GetHandleId(subject), StringHash(name))
endfunction
function GetHandleWidget takes handle subject, string name returns widget
    return LoadWidgetHandle(HATable(), GetHandleId(subject), StringHash(name))
endfunction
function GetHandleLocation takes handle subject, string name returns location
    return LoadLocationHandle(HATable(), GetHandleId(subject), StringHash(name))
endfunction
function GetHandlePlayer takes handle subject, string name returns player
    return LoadPlayerHandle(HATable(), GetHandleId(subject), StringHash(name))
endfunction
function GetHandleRegion takes handle subject, string name returns region
    return LoadRegionHandle(HATable(), GetHandleId(subject), StringHash(name))
endfunction
function GetHandleRect takes handle subject, string name returns rect
    return LoadRectHandle(HATable(), GetHandleId(subject), StringHash(name))
endfunction
function GetHandleForce takes handle subject, string name returns force
    return LoadForceHandle(HATable(), GetHandleId(subject), StringHash(name))
endfunction
function GetHandleFogmodifier takes handle subject, string name returns fogmodifier
    return LoadFogModifierHandle(HATable(), GetHandleId(subject), StringHash(name))
endfunction
function GetHandleTimerDialog takes handle subject, string name returns timerdialog
    return LoadTimerDialogHandle(HATable(), GetHandleId(subject), StringHash(name))
endfunction

function HaveHandleHandle takes handle subject, string name returns boolean
    return HaveSavedHandle(HATable(), GetHandleId(subject), StringHash(name))
endfunction
function HaveHandleInt takes handle subject, string name returns boolean
    return HaveSavedInteger(HATable(), GetHandleId(subject), StringHash(name))
endfunction
function HaveHandleReal takes handle subject, string name returns boolean
    return HaveSavedReal(HATable(), GetHandleId(subject), StringHash(name))
endfunction
function HaveHandleString takes handle subject, string name returns boolean
    return HaveSavedString(HATable(), GetHandleId(subject), StringHash(name))
endfunction
function HaveHandleBoolean takes handle subject, string name returns boolean
    return HaveSavedBoolean(HATable(), GetHandleId(subject), StringHash(name))
endfunction

function RemoveHandle takes handle subject, string name returns nothing
    call SaveAgentHandle(HATable(),GetHandleId(subject),StringHash(name), null)
    call RemoveSavedHandle(HATable(),GetHandleId(subject),StringHash(name))
endfunction
function RemoveInt takes handle subject, string name returns nothing
    call SaveInteger(HATable(),GetHandleId(subject),StringHash(name), 0)
    call RemoveSavedInteger(HATable(),GetHandleId(subject),StringHash(name))
endfunction
function RemoveReal takes handle subject, string name returns nothing
    call SaveReal(HATable(),GetHandleId(subject),StringHash(name), 0.0)
    call RemoveSavedReal(HATable(),GetHandleId(subject),StringHash(name))
endfunction
function RemoveBoolean takes handle subject, string name returns nothing
    call SaveBoolean(HATable(),GetHandleId(subject),StringHash(name), false)
    call RemoveSavedBoolean(HATable(),GetHandleId(subject),StringHash(name))
endfunction
function RemoveStr takes handle subject, string name returns nothing
    call SaveStr(HATable(),GetHandleId(subject),StringHash(name), null)
    call RemoveSavedString(HATable(),GetHandleId(subject),StringHash(name))
endfunction

function FlushHandle takes handle subject returns nothing
    call FlushChildHashtable(HATable(), GetHandleId(subject) )
endfunction
 

RaiJin

New Member
Reaction score
40
completely pointess, there's no need for this because vex already wrote one...reinvent the wheel ? :S
 

black.sheep

Active Member
Reaction score
24
Eh, helps me.
I luv you, my map would've required serious work to fix if it wasnt for this.
But no FlushHandleLocals funct FTL.
 

jwallstone

New Member
Reaction score
33
@blacksheep
I thought this might at least help some people who were still using the old system. It does have a flushing function, though I think I changed the name to FlushHandle. But it does exactly the same thing and you can just rename it.

I did find Vex's version:
http://www.wc3c.net/showthread.php?t=106558&highlight=Faux+Handle+Vars

There are a few important differences: his is trying to reproduce Local Handle Vars EXACTLY. However, there are a few major changes now that I think need to be reflected in the code. They are noted above in the original post too.

First, only Agents can be saved, not all handles, so the main saving function name was changed to reflect this. It's important for people to at least see this so they don't try to save other handles and have all sorts of problems.

Second, the old LHV deleted entries by having people save sort of a "default" value, like 0, null, or false, over the old entry. This behavior is quite faulty/buggy for several reasons and is poor programming practice.

1. By using this method to save new values, you prevent anybody from actually using those "default" values as valid entries. 0 is no longer a valid number to store, nor is false, etc. If you should ever try to save one of those values and later on check if something is stored in that entry with HaveSaved_blank_, then your code will fail.

2. Deleting entries by simply storing a new value makes code unreadable and confusing. People would have no clear idea whether someone is actually trying to save a value for later use or just deleting it. The old way was always horribly counterintuitive. Since there are explicit Remove functions, it's a lot better this way to actually call a Remove function when you want to remove.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
So, if you want it able to attach handles, use a wrapper like this :
JASS:
struct HandleWrap
handle data
endstruct
 

Romek

Super Moderator
Reaction score
964
Moved to Graveyard.
 

black.sheep

Active Member
Reaction score
24
Err, problem.
This doesnt seem to work for me. Neither does Vexs version. This one either has issues with attaching or getting handles and Vexs version crashes my JassHelper.
Help?
 
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
    +1
  • V-SNES V-SNES:
    Happy Friday!
    +1

      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