Confused about leaks... insanely confused... -.-

Level 12
Joined
Oct 16, 2010
Messages
644
I've been looking at trying to learn how to remove leaks. I decided to start with unit groups, I don't think that's gone too bad. But then I saw things like location leaks and player group leaks. And there are loads of different variables needed? I'm confused. The main trigger I want shown to me is posted below (it's an AI system I made for my map).

  • AI Train
    • Events
      • Time - Every 15.00 seconds of game time
    • Conditions
    • Actions
      • Player Group - Pick every player in (All players controlled by a Computer player) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Or - Any (Conditions) are true
                • Conditions
                  • ((Number of units in (Units owned by (Picked player) of type Plantation)) x 15) Greater than or equal to ((Picked player) Food used)
                  • ((Picked player) Current lumber) Greater than or equal to (((Picked player) Food used) - 1)
            • Then - Actions
              • -------- Train Monk --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Picked player) Current gold) Greater than or equal to 300
                  • ((Picked player) Food used) Less than ((Picked player) Food cap)
                  • ((Picked player) Food used) Greater than or equal to ((Number of units in (Units owned by (Picked player) of type Monk)) x 10)
                • Then - Actions
                  • Unit - Order (Random unit from (Units owned by (Picked player) of type Church)) to train/upgrade to a Monk
                • Else - Actions
              • -------- Train Balista, Catapult or Cannon --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Number of units in (Units owned by (Picked player) matching (((Unit-type of (Matching unit)) Equal to Ballista) or (((Unit-type of (Matching unit)) Equal to Catapult) or ((Unit-type of (Matching unit)) Equal to Cannon))))) Less than or equal to (Integer(((Real(((Picked player) Food cap))) x 0.05)))
                • Then - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • ((Picked player) Current gold) Greater than or equal to 800
                      • (Number of units in (Units owned by (Picked player) of type Mine)) Greater than or equal to 3
                      • (Current research level of Chemistry for (Picked player)) Equal to 0
                      • (Current research level of Age 2 for (Picked player)) Greater than or equal to 2
                      • (Random integer number between 1 and 2) Equal to 1
                      • ((Picked player) Food used) Less than ((Picked player) Food cap)
                    • Then - Actions
                      • Unit - Order (Random unit from (Units owned by (Picked player) of type Workshop)) to train/upgrade to a Ballista
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • ((Picked player) Current gold) Greater than or equal to 760
                          • (Number of units in (Units owned by (Picked player) of type Mine)) Greater than or equal to 3
                          • (Current research level of Chemistry for (Picked player)) Equal to 0
                          • (Current research level of Age 2 for (Picked player)) Greater than or equal to 2
                          • ((Picked player) Food used) Less than ((Picked player) Food cap)
                        • Then - Actions
                          • Unit - Order (Random unit from (Units owned by (Picked player) of type Workshop)) to train/upgrade to a Catapult
                        • Else - Actions
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • ((Picked player) Current gold) Greater than or equal to 1160
                              • (Number of units in (Units owned by (Picked player) of type Mine)) Greater than or equal to 5
                              • (Current research level of Chemistry for (Picked player)) Equal to 1
                              • (Current research level of Age 2 for (Picked player)) Equal to 3
                              • ((Picked player) Food used) Less than ((Picked player) Food cap)
                            • Then - Actions
                              • Unit - Order (Random unit from (Units owned by (Picked player) of type Workshop)) to train/upgrade to a Cannon
                            • Else - Actions
                • Else - Actions
              • -------- Train Light Cavalry, Mounted Skirmisher, Heavy Cavalry or Paladin. --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Number of units in (Units owned by (Picked player) matching (((Unit-type of (Matching unit)) Equal to Light Cavalry) or (((Unit-type of (Matching unit)) Equal to Mounted Skirmisher) or (((Unit-type of (Matching unit)) Equal to Heavy Cavalry) or ((Unit-type o Less than or equal to (Integer(((Real(((Picked player) Food cap))) x 0.10)))
                • Then - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • ((Picked player) Current gold) Greater than or equal to 275
                      • (Number of units in (Units owned by (Picked player) of type Mine)) Greater than or equal to 2
                      • (Current research level of Age 2 for (Picked player)) Less than or equal to 1
                      • (Random integer number between 1 and 2) Equal to 1
                      • ((Picked player) Food used) Less than ((Picked player) Food cap)
                    • Then - Actions
                      • Unit - Order (Random unit from (Units owned by (Picked player) of type Stables)) to train/upgrade to a Light Cavalry
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • ((Picked player) Current gold) Greater than or equal to 280
                          • (Number of units in (Units owned by (Picked player) of type Mine)) Greater than or equal to 2
                          • (Current research level of Age 2 for (Picked player)) Less than or equal to 1
                          • ((Picked player) Food used) Less than ((Picked player) Food cap)
                        • Then - Actions
                          • Unit - Order (Random unit from (Units owned by (Picked player) of type Stables)) to train/upgrade to a Mounted Skirmisher
                        • Else - Actions
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • ((Picked player) Current gold) Greater than or equal to 340
                              • (Number of units in (Units owned by (Picked player) of type Mine)) Greater than or equal to 3
                              • (Current research level of Age 2 for (Picked player)) Greater than or equal to 3
                              • (Current research level of Squires for (Picked player)) Not equal to 1
                              • ((Picked player) Food used) Less than ((Picked player) Food cap)
                            • Then - Actions
                              • Unit - Order (Random unit from (Units owned by (Picked player) of type Stables)) to train/upgrade to a Heavy Cavalry
                            • Else - Actions
                              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                • If - Conditions
                                  • ((Picked player) Current gold) Greater than or equal to 450
                                  • (Number of units in (Units owned by (Picked player) of type Mine)) Greater than or equal to 4
                                  • (Current research level of Age 2 for (Picked player)) Greater than or equal to 3
                                  • (Current research level of Squires for (Picked player)) Equal to 1
                                  • ((Picked player) Food used) Less than ((Picked player) Food cap)
                                • Then - Actions
                                  • Unit - Order (Random unit from (Units owned by (Picked player) of type Stables)) to train/upgrade to a Paladin
                                • Else - Actions
                • Else - Actions
              • -------- Train Archer, Skirmisher or Crossbowman --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Number of units in (Units owned by (Picked player) matching (((Unit-type of (Matching unit)) Equal to Archer) or (((Unit-type of (Matching unit)) Equal to Skirmisher) or ((Unit-type of (Matching unit)) Equal to Crossbowman))))) Less than or equal to (Integer(((Real(((Picked player) Food cap))) x 0.15)))
                • Then - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • ((Picked player) Current gold) Greater than or equal to 270
                      • (Number of units in (Units owned by (Picked player) of type Mine)) Greater than or equal to 2
                      • (Current research level of Age 2 for (Picked player)) Equal to 1
                      • ((Picked player) Food used) Less than ((Picked player) Food cap)
                    • Then - Actions
                      • Unit - Order (Random unit from (Units owned by (Picked player) of type Archery)) to train/upgrade to a Archer
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • ((Picked player) Current gold) Greater than or equal to 270
                          • (Number of units in (Units owned by (Picked player) of type Mine)) Greater than or equal to 2
                          • (Current research level of Age 2 for (Picked player)) Equal to 1
                          • ((Picked player) Food used) Less than ((Picked player) Food cap)
                        • Then - Actions
                          • Unit - Order (Random unit from (Units owned by (Picked player) of type Archery)) to train/upgrade to a Skirmisher
                        • Else - Actions
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • ((Picked player) Current gold) Greater than or equal to 255
                              • (Number of units in (Units owned by (Picked player) of type Mine)) Greater than or equal to 4
                              • (Current research level of Age 2 for (Picked player)) Equal to 2
                              • ((Picked player) Food used) Less than ((Picked player) Food cap)
                            • Then - Actions
                              • Unit - Order (Random unit from (Units owned by (Picked player) of type Archery)) to train/upgrade to a Crossbowman
                            • Else - Actions
                              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                • If - Conditions
                                  • ((Picked player) Current gold) Greater than or equal to 320
                                  • (Number of units in (Units owned by (Picked player) of type Mine)) Greater than or equal to 4
                                  • (Current research level of Age 2 for (Picked player)) Greater than or equal to 3
                                  • (Current research level of Fire Arrows for (Picked player)) Equal to 0
                                  • ((Picked player) Food used) Less than ((Picked player) Food cap)
                                • Then - Actions
                                  • Unit - Order (Random unit from (Units owned by (Picked player) of type Archery)) to train/upgrade to a Crossbowman
                                • Else - Actions
                                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                    • If - Conditions
                                      • ((Picked player) Current gold) Greater than or equal to 320
                                      • (Number of units in (Units owned by (Picked player) of type Mine)) Greater than or equal to 4
                                      • (Current research level of Age 2 for (Picked player)) Greater than or equal to 3
                                      • (Current research level of Fire Arrows for (Picked player)) Equal to 1
                                      • (Random integer number between 1 and 2) Equal to 1
                                      • ((Picked player) Food used) Less than ((Picked player) Food cap)
                                    • Then - Actions
                                      • Unit - Order (Random unit from (Units owned by (Picked player) of type Archery)) to train/upgrade to a Crossbowman
                                    • Else - Actions
                                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                        • If - Conditions
                                          • ((Picked player) Current gold) Greater than or equal to 270
                                          • (Current research level of Age 2 for (Picked player)) Greater than or equal to 3
                                          • (Current research level of Fire Arrows for (Picked player)) Equal to 1
                                          • ((Picked player) Food used) Less than ((Picked player) Food cap)
                                        • Then - Actions
                                          • Unit - Order (Random unit from (Units owned by (Picked player) of type Archery)) to train/upgrade to a Archer
                                        • Else - Actions
                • Else - Actions
              • -------- Train Man-at-Arms, Footman, Spearman, Swordsman or Templar --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Number of units in (Units owned by (Picked player) matching (((Unit-type of (Matching unit)) Equal to Man-at-Arms) or (((Unit-type of (Matching unit)) Equal to Footman) or (((Unit-type of (Matching unit)) Equal to Pikeman) or (((Unit-type of (Matching unit)) Less than or equal to (Integer(((Real(((Picked player) Food cap))) x 0.60)))
                • Then - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • ((Picked player) Current gold) Greater than or equal to 120
                      • (Current research level of Age 2 for (Picked player)) Equal to 0
                      • ((Picked player) Food used) Less than or equal to ((Picked player) Food cap)
                    • Then - Actions
                      • Unit - Order (Random unit from (Units owned by (Picked player) of type Barracks)) to train/upgrade to a Man-at-Arms
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • ((Picked player) Current gold) Greater than or equal to 230
                          • ((Picked player) Current gold) Less than 280
                          • (Number of units in (Units owned by (Picked player) of type Mine)) Greater than or equal to 2
                          • (Current research level of Age 2 for (Picked player)) Equal to 1
                          • ((Picked player) Food used) Less than ((Picked player) Food cap)
                        • Then - Actions
                          • Unit - Order (Random unit from (Units owned by (Picked player) of type Barracks)) to train/upgrade to a Footman
                        • Else - Actions
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • ((Picked player) Current gold) Greater than or equal to 280
                              • (Number of units in (Units owned by (Picked player) of type Mine)) Greater than or equal to 2
                              • (Current research level of Age 2 for (Picked player)) Equal to 1
                              • ((Picked player) Food used) Less than ((Picked player) Food cap)
                            • Then - Actions
                              • Unit - Order (Random unit from (Units owned by (Picked player) of type Barracks)) to train/upgrade to a Footman
                            • Else - Actions
                              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                • If - Conditions
                                  • ((Picked player) Current gold) Greater than or equal to 300
                                  • (Number of units in (Units owned by (Picked player) of type Mine)) Greater than or equal to 3
                                  • (Current research level of Age 2 for (Picked player)) Greater than or equal to 2
                                  • (Current research level of Arenas for (Picked player)) Equal to 0
                                  • ((Picked player) Food used) Less than ((Picked player) Food cap)
                                • Then - Actions
                                  • Unit - Order (Random unit from (Units owned by (Picked player) of type Barracks)) to train/upgrade to a Swordsman
                                • Else - Actions
                                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                    • If - Conditions
                                      • ((Picked player) Current gold) Greater than or equal to 420
                                      • (Number of units in (Units owned by (Picked player) of type Mine)) Greater than or equal to 4
                                      • (Current research level of Age 2 for (Picked player)) Equal to 3
                                      • (Current research level of Arenas for (Picked player)) Equal to 1
                                      • ((Picked player) Food used) Less than ((Picked player) Food cap)
                                    • Then - Actions
                                      • Unit - Order (Random unit from (Units owned by (Picked player) of type Barracks)) to train/upgrade to a Templar
                                    • Else - Actions
                • Else - Actions
            • Else - Actions
          • -------- Train Villager or Peasant --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked player) Current gold) Greater than or equal to 40
              • ((Picked player) Food cap) Greater than or equal to ((Number of units in (Units owned by (Picked player) of type Villager)) x 50)
            • Then - Actions
              • Unit - Order (Random unit from (Units owned by (Picked player) of type Town Center)) to train/upgrade to a Villager
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Picked player) Current gold) Greater than or equal to 65
                  • ((Picked player) Food cap) Greater than or equal to ((Number of units in (Units owned by (Picked player) of type Peasant)) x 50)
                • Then - Actions
                  • Unit - Order (Random unit from (Units owned by (Picked player) of type Town Center)) to train/upgrade to a Peasant
                • Else - Actions
 
Level 20
Joined
Jul 14, 2011
Messages
3,214
Leak: An amount of data the game creates to handle something that becomes unaccessable and has no use.

There are some things that doesn't leak like (All Players) -> Player Group, and (Units in Playable map area) -> Unit Group

Leaks in red:
· (All players controlled by a Computer player)
· ((Number of units in (Units owned by (Picked player) of type Plantation)) x 15) Greater than or equal to ((Picked player) Food used) Pick every unit of type leaks twice
· ((Picked player) Food used) Greater than or equal to ((Number of units in (Units owned by (Picked player) of type Monk)) x 10) Pick every unit of type leaks twice
· Unit - Order (Random unit from (Units owned by (Picked player) of type Church)) to train/upgrade to a Monk Pick every unit of type leaks twice

You basically repeat the same leaks over and over.

1- WHENEVER you do something with a special effect, set the special effect or the effect handle into some variable and clean/destroy it later.
2- WHENEVER you do something with a Unit Group, declare the group into a variable and destroy it later.
3- WHENEVER you do something with a Player Group (other than All Players) declare it into a variable and destroy it later.
4- WHENEVER you create a lightning, declare it into some variable and destroy it later.
5- WHENEVER you use a Point (Point with Offset uses 2 point, the base, and the offset) declare it into some variable and destroy it later.

NOTE: Destroy only those you'll no longer use. If you have a "SoldierGroup" just create it and work with it, there's no need to destroy it. If you have Player Groups like DOTA (Sentinel / Scourge) just create those and don't destroy them.

6- REDUCE THE AMOUNT OF PARENTHESES! GOD! Whenever you see a pair of those ()'s the system has to call some data. "Set (Picked Player) Gold = (Picked Player) Gold + (Picked Player Gold + 2 x 5 / (Picked Player Wood))) blah blah. Damn it, you're telling the system to look OVER AND OVER for the same player. Just tell the system which player you want to handle (Set P = Picked Player) and tell the system "Hey, do you remember that guy I talked you about, well, add him 500 gold". Set P gold = P Gold + P Wood.

WHENEVER you're using a Unit, Player, Ability, Integer, etc., more than twice, declare it into a variable and work with the variable.

Look around for ways to destroy/clean leaks. There are several lists arond of Custom Scripts to do so (Call DestroyGroup(unitgroup), Call RemoveLocation(point), Call DestroyForce(playergroup), Call DestroyEffect(effect))

About Unit Groups: If you're using static groups (Church, Monks, Barracks), Trigger than, if a unit enters playable map area and unit type is Church/Monk/Barrack, add them to already created Church, Monk, Barrack groups. That way you don't have to order random unit of Units of Type which leaks twice, but you just pick a unit from a group you've already created and won't like, since you're using it.

If you use "Pick every unit of type Monk" and later you do the same thing, it will leak twice. The game doesn't remember "Hey, I already picked the units of this group, let's get that group I created before and work with it". It just "moves on" and leaves discarded data as leak trash.

Things that doesn't leak: Reals, Integers, Units (unles they're locals), Booleans, and some other i don't remember.
 
Level 20
Joined
Jul 14, 2011
Messages
3,214
Helps, but sometimes tells you there're leaks where there aren't, and doesn't tell you there are some leaks, where they are.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
In much more easier situation that we can relate to leak is;
- You are eating Sirloin with all kinds of sauces on a plate
- Then you put the leftover in a sink and you don't clean them
- What would happen if you don't clean the dish, forever ?
- It would eat up your space
 
Level 20
Joined
Jul 14, 2011
Messages
3,214
No. it's creating one group for each type of unit you're going to handle over and over, so you don't have to pick them over and over..
 
Top