• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

HIVE

Uncle
Uncle
They're called Locations when working with Hashtables. Save Location Handle is the name of the Action:
  • Events
    • Map initialization
  • Conditions
  • Actions
    • Set Variable PN = 1
    • Set Variable Point[1] = ...
    • Set Variable Point[2] = ...
    • Set Variable Point[3] = ...
    • Set Variable Point[4] = ...
    • For each integer Loop from 1 to 4 do
      • Loop - Actions
        • Hashtable - Save Handle of Point[Loop] as Loop of PN in YourHashtable
    • -------- Repeat this process for each Player Number (PN) --------
    • Set Variable PN = 2
    • Set Variable Point[1] = ...
    • Set Variable Point[2] = ...
    • Set Variable Point[3] = ...
    • Set Variable Point[4] = ...
    • For each integer Loop from 1 to 4 do
      • Loop - Actions
        • Hashtable - Save Handle of Point[Loop] as Loop of PN in YourHashtable
You can then reference any of these 4 Points by Loading them:
  • Actions
    • Set Variable Player = Player 4 (Purple)
    • Set Variable PN = (Player number of Player)
    • Unit - Create 1 Footman for Player at (Load 2 of PN from YourHashtable) facing...
That would create a Footman for Player 4 at their second Point (so Point[2] from earlier).
Gnuoy
Gnuoy
Oh that's easier than I thought. IDK why i've been intimidated from this for so long.

  • altar pt hashtable
    • Events
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set VariableSet kni_king_altars_hashtable = (Last created hashtable)
      • Hashtable - Save Handle OfYellow_Red_Altar as 5 of 1 in kni_king_altars_hashtable.
      • Hashtable - Save Handle OfYellow_Blue_Altar as 5 of 2 in kni_king_altars_hashtable.
      • Hashtable - Save Handle OfYellow_Teal_Altar as 5 of 3 in kni_king_altars_hashtable.
      • Hashtable - Save Handle OfYellow_Purp_Altar as 5 of 4 in kni_king_altars_hashtable.

  • Unit - Create 1 hire_buttons_knights_array[leave_loop_integer] for Neutral Passive at (Load (Player number of Player_array_var[leave_loop_integer]) of 1 in (Last created hashtable).) facing Default building facing degrees

so this would reference the "yellow_red_altar"?
Uncle
Uncle
Assuming (Player number of Player_array_var[leave_loop_integer]) is equal to 5, then yes, it would reference Yellow_Red_Altar.

Just don't use RemoveLocation() on these, they're intended to exist forever.
Gnuoy
Gnuoy
yes these are intended to exist forever / be constant for the duration of the game
Uncle
Uncle
Good, and to clarify, in my example where I suggested to repeatedly use Point[1 -> 4] you wouldn't have to Remove them because they're being stored in the Hashtable. This is the rare case where my "golden rule" of always Removing a Point before Setting it again doesn't apply.
Gnuoy
Gnuoy
it works. i wish i used best practices from the beginning of this project.
Gnuoy
Gnuoy
well why is removing a point a golden rule? I thought simply setting the point again will "move" the point and not create a leak?
I understand why it doesn't apply to the hashtable we talked about above because those are static points.
Uncle
Uncle
This leaks a Point:
  • Set Variable TempPoint = somewhere
  • Set Variable TempPoint = somewhere
Because our first usage of TempPoint was never removed. The Location object that it created is no longer referenceable and without a reference we can't get rid of it. That's what a memory leak is, something that exists in the game's memory that you no longer have access to.

The golden rule is to always Remove your Point variable before Setting it again to avoid memory leaks. For constant/static variables you would only ever Set them once anyway so they're excluded.

And it doesn't apply to the Hashtable example because the Locations are being saved in the hashtable. You can't leak something that you always have access to.
  • Like
Reactions: Gnuoy
Gnuoy
Gnuoy
So udg_ran_tar_pt_two is leaking here?
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • defeat_counter Equal to 4
    • Then - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Tree of Eternity 0008 <gen> is alive) Equal to True
        • Then - Actions
          • Set VariableSet ran_target = Tree of Eternity 0008 <gen>
          • Set VariableSet ran_tar_pt_two = ran_tar_pt[5]
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ancient of War 0011 <gen> is alive) Equal to True
        • Then - Actions
          • Set VariableSet ran_target = Ancient of War 0011 <gen>
          • Set VariableSet ran_tar_pt_two = ran_tar_pt[2]
        • Else - Actions
    • Else - Actions
Top