• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Trigger] Hashtable testing with Knockback

Status
Not open for further replies.
Level 10
Joined
Aug 15, 2008
Messages
720
Since I learned these hashtables, I was testing them.

I was creating knockback trigger with hashtable method (as wyrm tutorial)

Thing is... I want that Knockback without leaks, so I did basic memory fixing method, but then basic Knockback only knocks one unit and in other castings it doesn't knock target, he just stands at his place.

Trigger:
  • Fire Fist
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Fire Fist
    • Actions
      • Set TrigUnit = (Triggering unit)
      • Set Target = (Target unit of ability being cast)
      • Set TargetUnitHandle = (Target unit of ability being cast)
      • Set TempLoc1 = (Position of TrigUnit)
      • Set TempLoc2 = (Position of Target)
      • -------- --------------- --------
      • Set FFKnockbackAngle = (Angle from TempLoc1 to TempLoc2)
      • Set FFKnockbackDistance = 20.00
      • Set RemainingTime = 1.00
      • -------- --------------- --------
      • Hashtable - Save FFKnockbackAngle as 0 of (Key TargetUnitHandle) in FFKnockbackTable
      • Hashtable - Save FFKnockbackDistance as 1 of (Key TargetUnitHandle) in FFKnockbackTable
      • Hashtable - Save RemainingTime as 2 of (Key TargetUnitHandle) in FFKnockbackTable
      • -------- --------------- --------
      • Unit Group - Add Target to FFKnockbackGroup
      • -------- --------------- --------
      • Custom script: call RemoveLocation(udg_TempLoc1)
      • Custom script: call RemoveLocation(udg_TempLoc2)
  • Fire Fist Knockback
    • Events
      • Time - Every 0.04 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in FFKnockbackGroup and do (Actions)
        • Loop - Actions
          • Set PickUnitHandle = (Picked unit)
          • Set PickUnit = (Picked unit)
          • Set TempLoc1 = (Position of PickUnit)
          • Set TempLoc2 = (TempLoc1 offset by FFKnockbackDistance towards FFKnockbackAngle degrees)
          • Set FFKnockbackAngle = (Load 0 of (Key PickUnitHandle) from FFKnockbackTable)
          • Set FFKnockbackDistance = (Load 1 of (Key PickUnitHandle) from FFKnockbackTable)
          • Set RemainingTime = (Load 2 of (Key PickUnitHandle) from FFKnockbackTable)
          • -------- --------------- --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • RemainingTime Greater than 0.00
            • Then - Actions
              • Unit - Move PickUnit instantly to TempLoc2
              • Special Effect - Create a special effect attached to the origin of PickUnit using Objects\Spawnmodels\Undead\ImpaleTargetDust\ImpaleTargetDust.mdl
              • -------- --------------- --------
              • Set SFX1 = (Last created special effect)
              • Special Effect - Destroy SFX1
              • -------- --------------- --------
              • Hashtable - Save (FFKnockbackDistance - 0.08) as 0 of (Key PickUnitHandle) in FFKnockbackTable
              • Hashtable - Save (RemainingTime - 0.04) as 2 of (Key PickUnitHandle) in FFKnockbackTable
            • Else - Actions
              • Hashtable - Clear all child hashtables of child (Key PickUnitHandle) in FFKnockbackTable
              • Unit Group - Remove PickUnit from RespawnGroup
              • -------- --------------- --------
              • Custom script: call RemoveLocation(udg_TempLoc1)
              • Custom script: call RemoveLocation(udg_TempLoc2)
So, I would appreciate if someone would tell me how to make this leak free and working.
 
Level 2
Joined
Sep 2, 2004
Messages
15
As to whether or not it's working, why don't you just test map?

For optimization, I'd suggest setting the temp location to null.

set udg_point = null

So that they acually get removed. RemoveLocation isn't enough.
 
Level 10
Joined
Aug 15, 2008
Messages
720
............ Dude, THEY ARE removed. Null would set Variable to Nothing, But Main location would still remain. Thats why you have to remove em. And yes I have tested, esle I wouldn't come up with this thread. All I want is to know where to put memory leak fixes so trigger would 100% work.
 
Lucky You ;)

  • Beast Attack
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Beast Attack
    • Actions
      • -------- ------------------------------------------------------------------------------------------------- --------
      • -------- Getting the Spell constants --------
      • -------- ------------------------------------------------------------------------------------------------- --------
      • Set Beast_Attack_Caster = (Triggering unit)
      • Set Beast_Attack_Target = (Target unit of ability being cast)
      • Set Beast_Attack_Ability_Level = (Level of (Ability being cast) for Beast_Attack_Caster)
      • Set Beast_Attack_Location = (Position of Beast_Attack_Caster)
      • Set Beast_Attack_Location2 = (Position of Beast_Attack_Target)
      • -------- ------------------------------------------------------------------------------------------------- --------
      • -------- Setting the Spell values --------
      • -------- ------------------------------------------------------------------------------------------------- --------
      • Set Beast_Attack_Max_Life = (Max life of Beast_Attack_Caster)
      • Set Beast_Attack_Damage_Splitter = 8
      • Set Beast_Attack_Atribute = (Strength of Beast_Attack_Caster (Include bonuses))
      • Set Beast_Attack_Life_Damage = (Beast_Attack_Max_Life / (Real(Beast_Attack_Damage_Splitter)))
      • Set Beast_Attack_Atribute_Damage = ((Real(Beast_Attack_Atribute)) x (Real(Beast_Attack_Ability_Level)))
      • Set Beast_Attack_Total_Damage = (Beast_Attack_Life_Damage + Beast_Attack_Atribute_Damage)
      • -------- ------------------------------------------------------------------------------------------------- --------
      • -------- Knockback Setings --------
      • -------- ------------------------------------------------------------------------------------------------- --------
      • Set KnockbackAngle = (Angle from Beast_Attack_Location to Beast_Attack_Location2)
      • Set KnockbackSpeed = 12.00
      • Set KnockbackDistance = 300.00
      • Hashtable - Save KnockbackSpeed as (Key speed) of (Key (Target unit of ability being cast)) in KnockbackTable
      • Hashtable - Save KnockbackAngle as (Key angle) of (Key (Target unit of ability being cast)) in KnockbackTable
      • Hashtable - Save KnockbackDistance as (Key distance) of (Key (Target unit of ability being cast)) in KnockbackTable
      • Unit - Pause Beast_Attack_Target
      • Unit - Turn collision for Beast_Attack_Target Off
      • Unit Group - Add Beast_Attack_Target to KnockbackUnits
      • -------- ------------------------------------------------------------------------------------------------- --------
      • -------- Damaging the target --------
      • -------- ------------------------------------------------------------------------------------------------- --------
      • Unit - Cause Beast_Attack_Caster to damage Beast_Attack_Target, dealing Beast_Attack_Total_Damage damage of attack type Spells and damage type Unknown
      • -------- ------------------------------------------------------------------------------------------------- --------
      • -------- Creating nice special effect --------
      • -------- ------------------------------------------------------------------------------------------------- --------
      • Special Effect - Create a special effect attached to the hand, left of Beast_Attack_Caster using units\human\phoenix\phoenix.mdl
      • Special Effect - Destroy (Last created special effect)
      • Special Effect - Create a special effect attached to the hand, right of Beast_Attack_Caster using units\human\phoenix\phoenix.mdl
      • Special Effect - Destroy (Last created special effect)
      • -------- ------------------------------------------------------------------------------------------------- --------
      • -------- Crreating Floating Text --------
      • -------- ------------------------------------------------------------------------------------------------- --------
      • Floating Text - Create floating text that reads ((String((Integer(Beast_Attack_Total_Damage)))) + !) above Beast_Attack_Caster with Z offset 0.00, using font size 10.00, color (100.00%, 5.00%, 5.00%), and 0.00% transparency
      • Floating Text - Change (Last created floating text): Disable permanence
      • Floating Text - Set the velocity of (Last created floating text) to 64.00 towards 90.00 degrees
      • Floating Text - Change the fading age of (Last created floating text) to 3.00 seconds
      • Floating Text - Change the lifespan of (Last created floating text) to 5.00 seconds
      • -------- ------------------------------------------------------------------------------------------------- --------
      • -------- Clearing leaks --------
      • -------- ------------------------------------------------------------------------------------------------- --------
      • Custom script: call RemoveLocation(udg_Beast_Attack_Location)
      • Custom script: call RemoveLocation(udg_Beast_Attack_Location2)
  • KnockbackUnits
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • -------- ------------------------------------------------------------------------------------------------- --------
      • -------- Leave this actions as they are/// You can add change special effects but that's it --------
      • -------- ------------------------------------------------------------------------------------------------- --------
      • Unit Group - Pick every unit in KnockbackUnits and do (Actions)
        • Loop - Actions
          • Set KnockbackSpeed = (Load (Key speed) of (Key (Picked unit)) from KnockbackTable)
          • Set KnockbackAngle = (Load (Key angle) of (Key (Picked unit)) from KnockbackTable)
          • Set KnockbackDistance = (Load (Key distance) of (Key (Picked unit)) from KnockbackTable)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • KnockbackDistance Greater than 0.00
            • Then - Actions
              • Set Knockback_Loc1 = (Position of (Picked unit))
              • Set Knockback_Loc2 = (Knockback_Loc1 offset by KnockbackSpeed towards KnockbackAngle degrees)
              • Destructible - Pick every destructible within 175.00 of Knockback_Loc1 and do (Destructible - Kill (Picked destructible))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Terrain pathing at Knockback_Loc2 of type Walkability is off) Equal to True
                • Then - Actions
                  • Unit - Unpause Beast_Attack_Target
                  • Unit - Turn collision for Knockback_Target On
                  • Custom script: call RemoveLocation(udg_Knockback_Loc1)
                  • Custom script: call RemoveLocation(udg_Knockback_Loc2)
                  • Hashtable - Clear all child hashtables of child (Key (Picked unit)) in KnockbackTable
                  • Unit Group - Remove (Picked unit) from KnockbackUnits
                • Else - Actions
                  • Unit - Move (Picked unit) instantly to Knockback_Loc2
                  • Special Effect - Create a special effect attached to the origin of (Picked unit) using Abilities\Weapons\AncientProtectorMissile\AncientProtectorMissile.mdl
                  • Special Effect - Destroy (Last created special effect)
                  • Hashtable - Save (KnockbackDistance - KnockbackSpeed) as (Key distance) of (Key (Picked unit)) in KnockbackTable
                  • Custom script: call RemoveLocation(udg_Knockback_Loc1)
                  • Custom script: call RemoveLocation(udg_Knockback_Loc2)
            • Else - Actions
              • Unit - Unpause Beast_Attack_Target
              • Unit - Turn collision for Knockback_Target On
              • Hashtable - Clear all child hashtables of child (Key (Picked unit)) in KnockbackTable
              • Unit Group - Remove (Picked unit) from KnockbackUnits
Well it's a bit different but based on the same thing + it contains a real spell in it, hope it helps =)
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
You can try
  • Custom script: call RemoveUnit(GetEnumUnit())
But think, that REMOVES the unit, thus removing it from the game totally. The thing you are confused with is a reference leak, the thing TheHellMan spoke of, only TheHellMan was wrong. Reference leaks are in effect on local variables, since they are totally not usable nor accesable after the function ends, thus if they still have a pointer (not nulled) they leak a reference. Globals stay the whole game, and thus dont leak a reference (maybe one, but it is re-used).

Though all handles (everything except string reals integers,booleans etc.) leak references, some also need other cleaning, such as Groups and Locations.

Key(Picked Unit) does not leak.
native GetHandleId takes handle h returns integer

This is the JASS function of Key(), as you can see, it returns an integer, and as you said, integers dont leak.

Have a good life! Remember not to eat too much, but not too little. Be nice to each other and help other people once in a while.
-Yixx,,-
 
Level 10
Joined
Aug 15, 2008
Messages
720
Thanks for clearing up with keys. But I don't need to remove units, I was asking does they leak, I would want to add Variables to those picked units.

Also Somekind of problem was in keys, what made my trigger un-working. Anyway Berzerker thanks, but I have another note. I like idea about turning collision and stopping knockbacking when unit is at wall, unpathable location and etc. BUT Your example of it doesn't work. Or else I am doing wrong.
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
i mean, locations have a cleaning function RemoveLocation(). I was trying to show you what would happen if you would use such a function on a unit, it would get totally removed. Thus it does not leak as in leaks a memory spot, at most a reference leak.
 
Status
Not open for further replies.
Top