Hashtable help/questions

afisakov

You can change this now in User CP.
Reaction score
37
Hello, I am very new to using hashtables
some Hopefully quick questions
1) does "RemoveSavedHandle" remove the unit like it sounds, or only destroy the reference and leave unit itself intact
2) does LoadItemHandle truly load/create something that needs to be removed? or is it more similar to referencing a variable
e.g. can I use SetUnitPosition(LoadUnitHandle(1,2), x, y) or do I need to use
Code:
set dummy= LoadUnitHandle(1,2)
call SetUnitPosition(dummy, x, y)
set dummy= null
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
Hashtables are extremely similar to variables with a few key differences and similarities:

Similarly:
Loading handles can replace the use of a variable of the same type
Setting null is the equivelant to removing a saved handle, however, the saved handle is not scope restricted, so it should be released when the handle is destroyed rather than at the end of a function etc

Differences (aka Efficiency vs Utility):
As everyone knows variables are relatively limited as far as array max size and global definitions etc, this is where hashtables are wonderfull... They are like a seemingly endless nested array that can use text values instead similar to json key value pairs etc.

Where hashtables fall short is their efficiency... while they have almost the same exact uses as variables it is less efficienct to save and load them than it is to access a variable, making them more usefull for thinks like long term storage. Typically if values are to be used more than once in a single function they are loaded at the beginning, and set to a local variable.
 

afisakov

You can change this now in User CP.
Reaction score
37
Can someone take a look at my trigger and see if I did this right?
I already tested that it functions in-game, but wanted to check thtat did not miss any leaks/cleanups, especiailly in regards to hashtables.

The spell creates ice pillars around target point, then they push inwards, compressing any units inside, deals damage and applies debuff at very end.

Activation
Code:
globals
   location array PillarSpot
   hashtable Pillars= InitHashtable()
endglobals

function Trig_Ice_Pillars_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A098'
endfunction

function Trig_Ice_Pillars_Actions takes nothing returns nothing
local integer pid= GetPlayerId(GetOwningPlayer(GetTriggerUnit())) + 1
local integer i=0
local unit u
local real x
local real y
local real angle
local real range= (240+80*GetUnitAbilityLevel(GetTriggerUnit(),'A098') )*(1.+ BoostValue[pid]*.5)
   set PillarSpot[pid]=GetSpellTargetLoc()
   set x= GetLocationX(PillarSpot[pid])
   set y= GetLocationY(PillarSpot[pid])
   loop
       exitwhen i>7
       set angle=bj_PI * 2 * i / 8.
       set u= CreateUnit(Player(15), 'e0xe', x + range*Cos(angle), y + range*Sin(angle), bj_UNIT_FACING)
       call UnitApplyTimedLife(u, 'BTLF', 10)
       set bj_lastCreatedEffect = AddSpecialEffectTarget("Doodads\\Icecrown\\Rocks\\IceBlock\\IceBlock3.mdl", u, "origin")
       call SaveEffectHandle(Pillars, pid, i+8, bj_lastCreatedEffect)
       call SaveUnitHandle(Pillars, pid, i, u)
       set u= null
       set i= i+1
   endloop
   call EnableTrigger(gg_trg_Ice_Pillars_Periodic)
endfunction

//===========================================================================
function InitTrig_Ice_Pillars takes nothing returns nothing
    set gg_trg_Ice_Pillars=CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Ice_Pillars, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(gg_trg_Ice_Pillars, Condition(function Trig_Ice_Pillars_Conditions))
    call TriggerAddAction(gg_trg_Ice_Pillars, function Trig_Ice_Pillars_Actions)
endfunction
Effect
Code:
function Trig_Ice_Pillars_Periodic_Actions takes nothing returns nothing
local integer i=0
local integer i2
local unit dummy
local unit target
local boolean activeCasts=false
local real boost
local real dist
local real angle
local real x
local real y
local group innerG
local group outerG
local real jump= 9
local real dmg
loop
   exitwhen i > 8
   set x=GetLocationX(PillarSpot[i])
   set y=GetLocationY(PillarSpot[i])
   if x!=0 then
//
   set boost= 1. +BoostValue[i]
   set dummy= LoadUnitHandle(Pillars, i, 0)
   set dist= SquareRoot( (GetUnitX(dummy)-x)*(GetUnitX(dummy)-x) + (GetUnitY(dummy)-y)*(GetUnitY(dummy)-y) )
   set dummy= null
   if dist > 160 then
       set outerG=GetUnitsInRangeOfLocMatching(dist * boost, PillarSpot[i], Condition(function ishostileUnit))
       set dist= dist -jump
       set innerG=GetUnitsInRangeOfLocMatching(dist , PillarSpot[i], Condition(function ishostileUnit))
       set activeCasts=true
       set i2= 0
       loop //move dummy effects
           exitwhen i2>7
           set angle= bj_PI *2 *i2 / 8.
           call SetUnitPosition(LoadUnitHandle(Pillars, i, i2), x +dist*Cos(angle), y +dist*Sin(angle) )
           set i2=i2+1
       endloop
   
       set dist=dist*.9
       loop //move outlier units inward
           set target=FirstOfGroup(outerG)
           exitwhen target == null
           call GroupRemoveUnit(outerG, target)
           if IsUnitInGroup(target, innerG)==false then
               set angle=Atan2((GetUnitY(target)-y), (GetUnitX(target)-x))
               call SetUnitPosition(target, x +dist*Cos(angle), y +dist*Sin(angle) )
               call SetUnitPathing(target, false)
           endif
           set target=null
       endloop
       call DestroyGroup(outerG)
       set outerG= null
       call DestroyGroup(innerG)
       set innerG= null
   else
       set i2=0
       loop
           exitwhen i2>7
           call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Undead\\FrostNova\\FrostNovaTarget.mdl", GetUnitX(LoadUnitHandle(Pillars, i, i2)), GetUnitY(LoadUnitHandle(Pillars, i, i2)) ))
           call DestroyEffect(LoadEffectHandle(Pillars, i, i2+8))
           call RemoveUnit(LoadUnitHandle(Pillars, i, i2))
           set i2= i2+1
       endloop
       call FlushChildHashtable(Pillars,i)
       call DestroyEffect(AddSpecialEffectLoc("Abilities\\Spells\\Undead\\FrostNova\\FrostNovaTarget.mdl", PillarSpot[i] ))
       set outerG=GetUnitsInRangeOfLocMatching(dist * boost, PillarSpot[i], Condition(function ishostile))
       call RemoveLocation(PillarSpot[i])
       set dmg= GetHeroInt(udg_PlayersCharacter[i],true)*GetUnitAbilityLevel(udg_PlayersCharacter[i],'A098')*boost
       loop // damage at the end
           set target=FirstOfGroup(outerG)
           exitwhen target == null
           call GroupRemoveUnit(outerG, target)
           call SetUnitPathing(target, true)
           call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Undead\\FrostNova\\FrostNovaTarget.mdl", GetUnitX(target), GetUnitY(target)))
           if GetUnitAbilityLevel(target, 'B01G')>0 then
               call UnitDamageTargetBJ(udg_PlayersCharacter[i], target, dmg*1.5*boost, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_MAGIC)
               call IssueTargetOrder(CreateDummyWithAbilityCoord(GetOwningPlayer(udg_PlayersCharacter[i]) , 'A0DS' , R2I(3*boost) , GetUnitX(target), GetUnitY(target)), "thunderbolt", target)
           else
               call UnitDamageTargetBJ(udg_PlayersCharacter[i], target, dmg, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_MAGIC)
               call IssueTargetOrder(CreateDummyWithAbilityCoord(GetOwningPlayer(udg_PlayersCharacter[i]) , 'A0DS' , R2I(2*boost) , GetUnitX(target), GetUnitY(target)), "thunderbolt", target)
           endif
           set target=null
       endloop
       call DestroyGroup(outerG)
       set outerG= null
   endif
//
   endif
   set i=i + 1
endloop

if activeCasts == false then
   call DisableTrigger(gg_trg_Ice_Pillars_Periodic)
endif
endfunction

//===========================================================================
function InitTrig_Ice_Pillars_Periodic takes nothing returns nothing
    set gg_trg_Ice_Pillars_Periodic=CreateTrigger()
    call TriggerRegisterTimerEventPeriodic(gg_trg_Ice_Pillars_Periodic, 0.03)
    call TriggerAddAction(gg_trg_Ice_Pillars_Periodic, function Trig_Ice_Pillars_Periodic_Actions)
endfunction

Thank you in advance
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • 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 The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      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