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

Does this trigger leak ?

Status
Not open for further replies.
Level 5
Joined
Feb 1, 2009
Messages
111
  • Brainwash
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to (==) Brainwash
    • Actions
      • Set BrainWash_Loc[(Player number of (Owner of (Triggering unit)))] = (Target point of ability being cast)
      • Set BrainWashed_Units[(Player number of (Owner of (Triggering unit)))] = (Units within 250.00 of BrainWash_Loc[(Player number of (Owner of (Triggering unit)))] matching ((((Matching unit) is alive) Equal to (==) True) and (((Matching unit) belongs to an enemy of (Owner of (Triggering unit))) Equal to (==) True)))
      • Set NonBrainwashed_Units[(Player number of (Owner of (Triggering unit)))] = (Units within 650.00 of BrainWash_Loc[(Player number of (Owner of (Triggering unit)))] matching ((((Matching unit) belongs to an enemy of (Owner of (Triggering unit))) Equal to (==) True) and ((((Matching unit) is alive) Equal to (==) True) and (((Matching un
        • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Number of units in NonBrainwashed_Units[(Player number of (Owner of (Triggering unit)))]) Greater than (>) 0
          • Then - Actions
            • Game - Display to (All players) the text: (String((Number of units in NonBrainwashed_Units[(Player number of (Owner of (Triggering unit)))])))
            • Unit Group - Pick every unit in BrainWashed_Units[(Player number of (Owner of (Triggering unit)))] and do (Actions)
              • Loop - Actions
                • Unit - Change ownership of (Picked unit) to Player[(Player number of (Owner of (Triggering unit)))] and Change color
              • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Player number of (Owner of (Casting unit))) Equal to (==) 1
                • Then - Actions
                  • Countdown Timer - Start Brainwash_Timer1 as a One-shot timer that will expire in ((2.00 x (Real((Level of Brainwash for (Triggering unit))))) + 5.00) seconds
                • Else - Actions
                  • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Player number of (Owner of (Casting unit))) Equal to (==) 2
                    • Then - Actions
                      • Countdown Timer - Start Brainwash_Timer2 as a One-shot timer that will expire in ((2.00 x (Real((Level of Brainwash for (Triggering unit))))) + 5.00) seconds
                    • Else - Actions
                      • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Player number of (Owner of (Casting unit))) Equal to (==) 3
                        • Then - Actions
                          • Countdown Timer - Start Brainwash_Timer3 as a One-shot timer that will expire in ((2.00 x (Real((Level of Brainwash for (Triggering unit))))) + 5.00) seconds
                        • Else - Actions
                          • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • (Player number of (Owner of (Casting unit))) Equal to (==) 4
                            • Then - Actions
                              • Countdown Timer - Start Brainwash_Timer4 as a One-shot timer that will expire in ((2.00 x (Real((Level of Brainwash for (Triggering unit))))) + 5.00) seconds
                            • Else - Actions
                              • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                • If - Conditions
                                  • (Player number of (Owner of (Casting unit))) Equal to (==) 5
                                • Then - Actions
                                  • Countdown Timer - Start Brainwash_Timer5 as a One-shot timer that will expire in ((2.00 x (Real((Level of Brainwash for (Triggering unit))))) + 5.00) seconds
                                • Else - Actions
                                  • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                    • If - Conditions
                                      • (Player number of (Owner of (Casting unit))) Equal to (==) 6
                                    • Then - Actions
                                      • Countdown Timer - Start Brainwash_Timer6 as a One-shot timer that will expire in ((2.00 x (Real((Level of Brainwash for (Triggering unit))))) + 5.00) seconds
                                    • Else - Actions
                                      • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                        • If - Conditions
                                          • (Player number of (Owner of (Casting unit))) Equal to (==) 7
                                        • Then - Actions
                                          • Countdown Timer - Start Brainwash_Timer7 as a One-shot timer that will expire in ((2.00 x (Real((Level of Brainwash for (Triggering unit))))) + 5.00) seconds
                                        • Else - Actions
                                          • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                            • If - Conditions
                                              • (Player number of (Owner of (Casting unit))) Equal to (==) 8
                                            • Then - Actions
                                              • Countdown Timer - Start Brainwash_Timer8 as a One-shot timer that will expire in ((2.00 x (Real((Level of Brainwash for (Triggering unit))))) + 5.00) seconds
                                            • Else - Actions
          • Else - Actions
            • Custom script: call Error_Brainwash( GetOwningPlayer( GetTriggerUnit() ), "You can only brainwash units if there are other enemy units nearby" )
      • Custom script: call RemoveLocation(udg_BrainWash_Loc[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))])
      • Custom script: call DestroyGroup (udg_NonBrainwashed_Units[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))])

NOTE: I have cleaned the following leak in another trigger:
  • Custom script: call DestroyGroup (udg_BrainWashed_Units[1])
 
We cant really say if group "BrainWashed_Units" leaks because, as you said you destroy it in another trigger.

If you can ensure that you destroy the group before a unit by the same player casts this spell again, then it's no leak.

If a second unit by the same player casts this spell before you destroy the group you have a leak.

Also, why is it called "call DestroyGroup (udg_BrainWashed_Units[1])"? That lets us think that you again use a big If/Then/Else construction to check the correct player.

You should use arrays instead. Here for example it could be:

  • Countdown Timer - Start Brainwash_Timer[PlayerNumberOfTriggeringPlayer] as a One-shot timer that will expire in ((2.00 x (Real((Level of Brainwash for (Triggering unit))))) + 5.00) seconds

Also if you use same function more often in a trigger, it is worth to store it into a vriable.

GOOD
  • Set Unit = TriggeringUnit
  • Unit - some actions with Unit
  • Unit - some actions with Unit
  • Unit - some actions with Unit
BAD
  • Unit - some actions with TriggeringUnit
  • Unit - some actions with TriggeringUnit
  • Unit - some actions with TriggeringUnit
 
Status
Not open for further replies.
Top