Memory Leaks for (Interger A)

Status
Not open for further replies.
Level 6
Joined
Nov 3, 2005
Messages
103
Yo's. Got these triggers that're causing me crazy lag so I started looking into how to fix them with custom lines of scripts.

Here's one of em:
Code:
HH Step Lions Fang
    Events
        Time - Every 0.02 seconds of game time
    Conditions
    Actions
        For each (Integer A) from 1 to 10, do (Actions)
            Loop - Actions
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        Ability_LionsFang_TimeFrozen[(Integer A)] Greater than 0.00
                    Then - Actions
                        Set Ability_LionsFang_TimeFrozen[(Integer A)] = (Ability_LionsFang_TimeFrozen[(Integer A)] - 1.00)
                    Else - Actions
                        Set Ability_LionsFang_Frozen[(Integer A)] = 0.00
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        Ability_LionsFang_Value[(Integer A)] Greater than or equal to 0.00
                    Then - Actions
                        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            If - Conditions
                                Ability_LionsFang_Frozen[(Integer A)] Equal to 0.00
                            Then - Actions
                                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                    If - Conditions
                                        Ability_LionsFang_Value[(Integer A)] Greater than 0.00
                                    Then - Actions
                                        Unit - Move Ability_LionsFang_Dummy[(Integer A)] instantly to ((Position of Ability_LionsFang_Dummy[(Integer A)]) offset by 35.00 towards Ability_LionsFang_Angle[(Integer A)] degrees)
                                        Set Ability_LionsFang_Value[(Integer A)] = (Ability_LionsFang_Value[(Integer A)] - 1.00)
                                        Unit Group - Pick every unit in (Units within 150.00 of (Position of Ability_LionsFang_Dummy[(Integer A)])) and do (Actions)
                                            Loop - Actions
                                                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                                    If - Conditions
                                                        And - All (Conditions) are true
                                                            Conditions
                                                                ((Picked unit) belongs to an enemy of (Owner of Ability_LionsFang_Dummy[(Integer A)])) Equal to True
                                                                ((Picked unit) is in Ability_LionsFang_Group[(Integer A)]) Equal to False
                                                                ((Picked unit) is alive) Equal to True
                                                                ((Picked unit) is A flying unit) Equal to False
                                                    Then - Actions
                                                        Set Ability_LionsFang_Frozen[(Integer A)] = 1.00
                                                        Set Ability_LionsFang_TimeFrozen[(Integer A)] = 3.00
                                                        Unit Group - Add (Picked unit) to Ability_LionsFang_Group[(Integer A)]
                                                        Unit - Cause HonorHero_Lothar[(Integer A)] to damage (Picked unit), dealing (35.00 + (Random real number between 0.00 and 5.00)) damage of attack type Spells and damage type Normal
                                                        Special Effect - Create a special effect attached to the chest of (Picked unit) using Abilities\Weapons\WingedSerpentMissile\WingedSerpentMissile.mdl
                                                        Special Effect - Destroy (Last created special effect)
                                                        Special Effect - Create a special effect attached to the chest of (Picked unit) using Abilities\Weapons\WingedSerpentMissile\WingedSerpentMissile.mdl
                                                        Special Effect - Destroy (Last created special effect)
                                                        Special Effect - Create a special effect at (Position of Ability_LionsFang_Dummy[(Integer A)]) using Abilities\Weapons\WingedSerpentMissile\WingedSerpentMissile.mdl
                                                        Special Effect - Destroy (Last created special effect)
                                                    Else - Actions
                                                        Do nothing
                                    Else - Actions
                                        Unit - Kill Ability_LionsFang_Dummy[(Integer A)]
                            Else - Actions
                                Do nothing
                    Else - Actions
                        Do nothing

Alright so I understand you have to call a line after each point within the trigger.
My question is would I have to create a separate temp variable for each ability, and would I have to call Integer A at the end of each of the custom script lines?
Custom script: call RemoveLocation (udg_Temp_Point)
Also, how would something like this look when coding for Integer A, if I had to?
 
Last edited:
Level 16
Joined
Mar 25, 2016
Messages
1,327
Your lag has nothing to do with memory leaks. If you get immediate lags, memory leaks are not the reason. Memory leaks fill up your memory over time and cause lag once you are running short on memory. It takes a while until they are noticeable.

There are also leaks in the trigger, but they are not the reason for the immediate lag. Integers don't leak.
Things That Leak

In your case you have a periodic trigger (0.02), combined with a loop (10) combined with a unit group. The unit group will be created 50 * 10 times per second.

The trigger is very inefficient. You could tell us what the spell is supposed to do. I am sure there is a much better way to achieve the same.



My question is would I have to create a separate temp variable for each ability, and would I have to call Integer A at the end of each of the custom script lines?
If they are only temporary, you can use the same for every trigger.
Trigger interuption can cause a lot of bugs, because all variables are global in GUI. You should not use (Integer A) or other shared globals, if the trigger could get interrupted by another trigger using the same globals.
Your trigger oparates on Integer A which is basically a global integer variable named bj_forLoopAIndex.
In the process of your trigger you deal damage to another unit. If that unit dies from the damage, all triggers with the event
  • Unit - A unit Dies
will run.
After they are completed, your original trigger will continue to run. If one of the triggers with the death event uses (Integer A) as well, you will get problems, because (Integer A) no longer has the value of your original trigger, because it was changed by another trigger.

It's better to define a custom loop variable for every trigger, unless you are 100% the trigger cannot be interrupted.
The same can happen to shared temporary variables.

The best solution is to use local variables, though they are more difficult to deal with, if you don't know how they work.


If you have a point array, you can use:
call RemoveLocation (udg_Temp_Point[0])
to access Integer A in custom script use:
call RemoveLocation (udg_Temp_Point[bj_forLoopAIndex])

Please use [trigger]...[/trigger] tags when posting GUI triggers.
 
Status
Not open for further replies.
Top