• 🏆 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!

[Solved] Does leaking affect skills?

Level 4
Joined
Mar 7, 2024
Messages
66
Most of my hero's skills do the same, can you help me see if there is a leak? Is unit_group leaking? If there is a leak, where do I need to fix it?.
HOII.PNG
 

Uncle

Warcraft Moderator
Level 65
Joined
Aug 10, 2018
Messages
6,647
You're leaking 3 times, once during the Unit Group creation and twice inside of your Loop - Actions. Also, you shouldn't be removing p5 inside of the Loop - Actions section, you want to Remove it AFTER you're done picking every unit (so outside and below it). That being said, you did have the right idea with p5 and you were halfway there.

Here are the most common memory leaks by type. Note that I will leave some out because I don't think they're worth discussing yet, we can worry about those later. Oh and my use of the word "All" here may be incorrect but again let's not go crazy overthinking it.

[Unit Groups]
All of these functions will leak a Unit Group:
1715145872612.png


[Player Groups]
All of these functions will leak a Player Group excluding All Players:
1715147601361.png


[Points]
If you see the words "Position of..." or "Center of..." or "Point of..." know that you're leaking a Point:
  • Actions
    • Unit - Create 1 Footman for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees
    • Item - Create Tome of Experience at (Position of (Last created unit))
    • Special Effect - Create a special effect at (Target point of ability being cast) using Abilities\Spells\Human\ThunderClap\ThunderClapCaster.mdl
I'm leaking 3 Points in the above trigger -> (Center of (Playable map area)), (Position of (Last created unit)), and (Target point of ability being cast).

[Special Effects]
These are very straight forward and the easiest to deal with. If you create a Special Effect and never Destroy it then you've created a memory leak. You can see that being done in the above trigger. A lot of the time you can simply use the (Destroy last created special effect) Action which will remove the memory leak and clean things up for you automatically. Note that if you intend for a Special Effect to exist forever then it is NOT considered a memory leak so you don't have to Destroy it.


[The Solution]
The solution to these memory leaks is to use Variables. What you want to do is Set a Unit Group, Player Group, or Point variable to whatever it is that causes the leak. Then you need to reference that Variable instead of the leaking function. Once you're finished referencing that Variable you would use one of the many Custom Script functions for removing that specific type of memory leak which will get rid of it for good.

Here are some example triggers that use the above solution. These are completely leak free:
  • Actions
    • Set Temp_Unit_Group = (Units in (Playable map area) owned by Player 1 (Red))
    • Unit Group - Pick every unit in Temp_Unit_Group and do (Actions)
      • Loop - Actions
        • Unit - Kill (Picked unit)
    • Custom script: call DestroyGroup( udg_Temp_Unit_Group )
  • Actions
    • Set Temp_Player_Group = (All players controlled by a User player)
    • Player Group - Pick every player in Temp_Player_Group and do (Actions)
      • Loop - Actions
        • Player - Add 100 to (Picked player).Current gold
    • Custom script: call DestroyForce( udg_Temp_Player_Group )
  • Actions
    • Set Temp_Point = (Center of (Playable map area))
    • Unit - Create 1 Footman for Player 1 (Red) at Temp_Point facing Default building facing degrees
    • Custom script: call RemoveLocation( udg_Temp_Point )
    • -------- --------
    • Set Temp_Point = (Position of (Last created unit))
    • Item - Create Tome of Experience at Temp_Point
    • Custom script: call RemoveLocation( udg_Temp_Point )
  • Actions
    • Set Temp_Point = (Center of (Playable map area))
    • Special Effect - Create a special effect at Temp_Point using Abilities\Spells\Human\ThunderClap\ThunderClapCaster.mdl
    • Special Effect - Destroy (Last created special effect)
    • Custom script: call RemoveLocation( udg_Temp_Point )
Here's some general rules and information about memory leaks:

1) When dealing with memory leaks you will follow this pattern:
Set Variable, Use Variable (multiple times if you'd like), Remove Variable.

If you break this pattern then you're doing something wrong and likely creating memory leaks.

2) If you intend for something to exist forever then do not worry about cleaning it up as it is NOT a memory leak. A memory leak only exists when you lose track of something that was meant to be discarded after you were done with it.

3) A nice way to avoid having to deal with memory leaks is to use "constant" variables. These are any Variables that you've Set once and only once with the intention to reuse them throughout your triggers. For example, you could use a constant Point variable to keep track of where you spawn enemy units every 30 seconds, assuming that the position doesn't change. With this design you can avoid having to deal with memory leaks since you already have an existing variable that you can rely on.

For a deeper explanation of what a memory leak is:
 
Last edited:
Level 4
Joined
Mar 7, 2024
Messages
66
Thank you, thanks to you my map is no longer leaking. As shown in the picture, I didn't do it well and it didn't work. Can you help me? The entire Neutral Hostile group (not including Neutral Hostile champions) that dies will be revived in 3 seconds at the death location. I did but it only revived 1 child, how can I revive them all?
HOII.PNG
 

Uncle

Warcraft Moderator
Level 65
Joined
Aug 10, 2018
Messages
6,647
Thank you, thanks to you my map is no longer leaking. As shown in the picture, I didn't do it well and it didn't work. Can you help me? The entire Neutral Hostile group (not including Neutral Hostile champions) that dies will be revived in 3 seconds at the death location. I did but it only revived 1 child, how can I revive them all?
View attachment 472278
When using the Point With Polar Offset function you actually need 2 Point variables to avoid the leak:
  • Set QUADIE1 = (Position of (Killing unit))
  • Set QUADIE2 = (QUADIE1 offset by 100.00 towards (Facing of (Killing unit)) degrees)
Also, you're removing the Point (QUADIE) in the wrong spot again. This time it needs to be inside of the Loop - Actions.

Remember that the Loop - Actions run once per (Picked unit). So if the GQUAI unit group had 10 units inside of it you'd be setting QUADIE ten times while only removing it once at the very end. That's still creating 9 memory leaks. Remember the rule: Set, Use, Remove.

But I think you're going about the trigger the wrong way. Here's what I think you want to do:
  • Respawn NH Units
    • Events
      • Unit - A unit owned by Neutral Hostile Dies
    • Conditions
      • ((Triggering unit) is A Hero) Equal to False
    • Actions
      • Wait 3.00 game-time seconds
      • Set VariableSet NH_Respawn_Point = (Position of (Triggering unit))
      • Unit - Create 1 (Unit-type of (Triggering unit)) for Neutral Hostile at NH_Respawn_Point facing Default building facing degrees
      • Custom script: call RemoveLocation( udg_NH_Respawn_Point )
This will revive non-Hero neutral hostile units 3.00 seconds after they die.

Some other things:

1) You never want to use a Wait action inside of a Loop - Actions. They either don't work at all or won't work the way you want them to, bad news either way. If you want to delay something like this then I suggest looking into Unit Indexing, Dynamic Indexing, and other advanced techniques. I have links in my signature.

2) Here's how you can post your triggers, please do this instead of posting pictures. It makes it easier for us to copy each other's work:
 
Last edited:
Level 4
Joined
Mar 7, 2024
Messages
66
I did it successfully, thank you, the trigger I posted I want when an animal appears, it will create a game event: when that animal's health drops to 700, a group of monsters will appear, Decreasing it to 1 will make the monsters disappear. I tried but it didn't work. Please help me fix this. :huh:
  • CHIM THAP EVENT
    • Events
      • Unit - A unit enters EVENT STARTS <gen>
    • Conditions
      • (Unit-type of (Entering unit)) Equal to Albatross
    • Actions
      • Set GTHAP = (Units in Monster appears <gen> owned by Neutral Hostile)
      • Set QUAITHAP = (Center of Monster appears <gen>)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Percentage life of (Entering unit)) Equal to 700.00
        • Then - Actions
          • Unit - Create 8 Satyr Hellcaller for Neutral Hostile at QUAITHAP facing Default building facing degrees
          • Unit - Create 8 Storm Wyrm for Neutral Hostile at QUAITHAP facing Default building facing degrees
          • Custom script: call RemoveLocation (udg_QUAITHAP)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Percentage life of (Entering unit)) Equal to 1.00
        • Then - Actions
          • Unit Group - Pick every unit in GTHAP and do (Actions)
            • Loop - Actions
          • Unit - Remove (Picked unit) from the game
        • Else - Actions
      • Custom script: call DestroyGroup (udg_GTHAP)
 

Uncle

Warcraft Moderator
Level 65
Joined
Aug 10, 2018
Messages
6,647
I did it successfully, thank you, the trigger I posted I want when an animal appears, it will create a game event: when that animal's health drops to 700, a group of monsters will appear, Decreasing it to 1 will make the monsters disappear. I tried but it didn't work. Please help me fix this. :huh:
Your trigger doesn't really make any sense. If you want to track the health (life) of a unit then you need to periodically check it's life. Your trigger currently checks the life the very moment the Albatross enters the Region. This will only happen once, unless it leaves the region and enters again.

Also, you're using Percentage of life which is a value between 0.00% and 100.00%. There is no such thing as having 700.00% life. You want to check if the unit has less than or equal to a certain amount of Life (NOT %).

But I think you're misunderstanding something fundamental about how triggers work. They do exactly what you tell them to do when you tell them to do it, they aren't going to magically know that you want to continuously check the life of the unit, you have to continuously check the life yourself.

Here's one way to handle it:
  • CHIM THAP EVENT
    • Events
      • Unit - A unit enters EVENT STARTS <gen>
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Albatross
    • Actions
      • Unit Group - Add (Triggering unit) to GTHAP
  • Events
    • Time - Every 0.01 seconds of game time
  • Conditions
  • Actions
    • Unit Group - Pick every unit in GTHAP and do (Actions)
      • Loop - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Life of (Picked unit)) Less than or equal to 700.00
            • (There are no enemies)
          • Then - Actions
            • -------- Create the enemies --------
          • Else - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Life of (Picked unit)) Less than or equal to 1.00
          • Then - Actions
            • -------- Remove the enemies --------
          • Else - Actions
I feel like you're trying to do things the wrong way, though. Do you really want to use this Albatross to spawn enemies or are you just confused about how to properly spawn the enemies in the first place?
 
Last edited:

Uncle

Warcraft Moderator
Level 65
Joined
Aug 10, 2018
Messages
6,647
I'm not sure what you're asking since I only understand English but here are some things that are wrong:

Delete this, it doesn't make any sense. The (Triggering unit) IS the (Entering unit):
  • Conditions
    • (Entering unit) Equal to (Triggering unit)
(Triggering unit) can be used in every single Unit-Event, it always refers to the Unit mentioned in the Event --> A unit enters CHIM EVENT <gen>

Hero level is an Integer so there's no reason to convert it to a Real:
  • (Real((Hero level of (Picked unit)))) Equal to 400.00
Change it to this:
  • (Hero level of (Picked unit)) Equal to 400
Using Equal To with Reals is asking for trouble since they can be imprecise.
 
Top