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

[Trigger] Does this leak?

Status
Not open for further replies.
Level 6
Joined
May 31, 2008
Messages
218
Simple question, does this trigger leak? Cause according to leack check it does leak.

  • Create food
    • Events
      • Time - Every 3.00 seconds of game time
    • Conditions
    • Actions
      • Do Multiple ActionsFor each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Player((Integer A))) Food cap) Greater than (>) 0
              • (Number of units in (Units owned by (Player((Integer A))) of type Food)) Equal to (==) 0
            • Then - Actions
              • Set foodpoint = (Center of Food place <gen>)
              • Unit - Create 1 Food for (Player((Integer A))) at foodpoint facing Default building facing (270.0) degrees
              • Set food_unit[(Integer A)] = (Last created unit)
              • Custom script: call RemoveLocation (udg_foodpoint)
            • Else - Actions
              • Do nothing
 
Level 6
Joined
May 31, 2008
Messages
218
Can a condition leak?
And according to leak checker it's this line that leaks.
  • Set food_unit[(Integer A)] = (Last created unit)
 
Level 6
Joined
May 31, 2008
Messages
218
This fixes it?

  • Create food
    • Events
      • Time - Every 3.00 seconds of game time
    • Conditions
    • Actions
      • Do Multiple ActionsFor each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • Set foodgroup = (Units owned by (Player((Integer A))) of type Food)
            • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • ((Player((Integer A))) Food cap) Greater than (>) 0
                • (Number of units in foodgroup) Equal to (==) 0
              • Then - Actions
                • Set foodpoint = (Center of Food place <gen>)
                • Unit - Create 1 Food for (Player((Integer A))) at foodpoint facing Default building facing (270.0) degrees
                • Set food_unit[(Integer A)] = (Last created unit)
                • Custom script: call RemoveLocation (udg_foodpoint)
              • Else - Actions
          • Custom script: call DestroyGroup (udg_foodgroup)
And since you said that would leak, is this also something that could leak if i wouldn't have those variables made for each condition, that before was checking for units excluding structures.
  • Income 120 player
    • Events
      • Time - incometimer expires
    • Conditions
    • Actions
      • Do Multiple ActionsFor each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • Set incomecount = (Number of living Wood Income units owned by (Player((Integer A))))
          • Player - Add ((20 x incomecount) + 20) to (Player((Integer A))) Current lumber
      • Do Multiple ActionsFor each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • Set incomegroup = (Units owned by (Player((Integer A))) matching (((Matching unit) is A structure) Equal to (==) False))
          • Set incomecount = (Number of living Food Income units owned by (Player((Integer A))))
            • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • (Number of units in incomegroup) Less than (<) 40
              • Then - Actions
                • Set incomereal[(Integer A)] = (((1.00 x (Real(incomecount))) + 3.00) x 1.00)
                • Player - Add (Integer(incomereal[(Integer A)])) to (Player((Integer A))) Food cap
              • Else - Actions
                • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                  • If - Conditions
                    • (Number of units in incomegroup) Less than (<) 55
                  • Then - Actions
                    • Set incomereal[(Integer A)] = (((1.00 x (Real(incomecount))) + 3.00) x 0.80)
                    • Player - Add (Integer(incomereal[(Integer A)])) to (Player((Integer A))) Food cap
                  • Else - Actions
                    • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                      • If - Conditions
                        • (Number of units in incomegroup) Less than (<) 70
                      • Then - Actions
                        • Set incomereal[(Integer A)] = (((1.00 x (Real(incomecount))) + 3.00) x 0.70)
                        • Player - Add (Integer(incomereal[(Integer A)])) to (Player((Integer A))) Food cap
                      • Else - Actions
                        • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                          • If - Conditions
                            • (Number of units in incomegroup) Less than (<) 85
                          • Then - Actions
                            • Set incomereal[(Integer A)] = (((1.00 x (Real(incomecount))) + 3.00) x 0.60)
                            • Player - Add (Integer(incomereal[(Integer A)])) to (Player((Integer A))) Food cap
                          • Else - Actions
                            • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                              • If - Conditions
                                • (Number of units in incomegroup) Less than (<) 100
                              • Then - Actions
                                • Set incomereal[(Integer A)] = (((1.00 x (Real(incomecount))) + 3.00) x 0.50)
                                • Player - Add (Integer(incomereal[(Integer A)])) to (Player((Integer A))) Food cap
                              • Else - Actions
                                • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                  • If - Conditions
                                    • (Number of units in incomegroup) Less than (<) 115
                                  • Then - Actions
                                    • Set incomereal[(Integer A)] = (((1.00 x (Real(incomecount))) + 3.00) x 0.40)
                                    • Player - Add (Integer(incomereal[(Integer A)])) to (Player((Integer A))) Food cap
                                  • Else - Actions
                                    • Set incomereal[(Integer A)] = (((1.00 x (Real(incomecount))) + 3.00) x 0.30)
                                    • Player - Add (Integer(incomereal[(Integer A)])) to (Player((Integer A))) Food cap
          • Custom script: call DestroyGroup (udg_incomegroup)
      • Do Multiple ActionsFor each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • Set incomegroup = (Units owned by (Player((Integer A))) matching (((Matching unit) is A structure) Equal to (==) False))
          • Set incomecount = (Number of living Gold Income units owned by (Player((Integer A))))
            • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • (Number of units in incomegroup) Less than (<) 40
              • Then - Actions
                • Player - Add ((((10 x incomecount) + 60) / 10) x 10) to (Player((Integer A))) Current gold
              • Else - Actions
                • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                  • If - Conditions
                    • (Number of units in incomegroup) Less than (<) 55
                  • Then - Actions
                    • Player - Add ((((10 x incomecount) + 60) / 10) x 8) to (Player((Integer A))) Current gold
                  • Else - Actions
                    • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                      • If - Conditions
                        • (Number of units in incomegroup) Less than (<) 70
                      • Then - Actions
                        • Player - Add ((((10 x incomecount) + 60) / 10) x 7) to (Player((Integer A))) Current gold
                      • Else - Actions
                        • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                          • If - Conditions
                            • (Number of units in incomegroup) Less than (<) 85
                          • Then - Actions
                            • Player - Add ((((10 x incomecount) + 60) / 10) x 6) to (Player((Integer A))) Current gold
                          • Else - Actions
                            • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                              • If - Conditions
                                • (Number of units in incomegroup) Less than (<) 100
                              • Then - Actions
                                • Player - Add ((((10 x incomecount) + 60) / 10) x 50) to (Player((Integer A))) Current gold
                              • Else - Actions
                                • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                  • If - Conditions
                                    • (Number of units in incomegroup) Less than (<) 115
                                  • Then - Actions
                                    • Player - Add ((((10 x incomecount) + 60) / 10) x 4) to (Player((Integer A))) Current gold
                                  • Else - Actions
                                    • Player - Add ((((10 x incomecount) + 60) / 10) x 3) to (Player((Integer A))) Current gold
          • Custom script: call DestroyGroup (udg_incomegroup)
 
Last edited:
Level 37
Joined
Mar 6, 2006
Messages
9,240
The first trigger is ok.

  • Set incomecount = (Number of living Wood Income units owned by (Player((Integer A))))

^Leaks.

  • Player - Add (Integer(incomereal[(Integer A)])) to (Player((Integer A))) Food cap
^There's no reason to have that in there so many times, since you're going to do it anyway. Move it out of the IF/THEN/ELSE, move it to right before the destroy unit group line.
 
Level 6
Joined
May 31, 2008
Messages
218
well thank you, rep it is. And i pretty much gotta go through all my triggers to check for those unit groups in "hidden" places. Never realised that it would cause leaks in that way.
 
that could work i think, depends on how the CreateNUnitsAtLoc() function works

JASS:
function CreateUnitAtLocSaveLast takes player id, integer unitid, location loc, real face returns unit
    if (unitid == 'ugol') then
        set bj_lastCreatedUnit = CreateBlightedGoldmine(id, GetLocationX(loc), GetLocationY(loc), face)
    else
        set bj_lastCreatedUnit = CreateUnitAtLoc(id, unitid, loc, face)
    endif

    return bj_lastCreatedUnit
endfunction
function CreateNUnitsAtLoc takes integer count, integer unitId, player whichPlayer, location loc, real face returns group
    call GroupClear(bj_lastCreatedGroup)
    loop
        set count = count - 1
        exitwhen count < 0
        call CreateUnitAtLocSaveLast(whichPlayer, unitId, loc, face)
        call GroupAddUnit(bj_lastCreatedGroup, bj_lastCreatedUnit)
    endloop
    return bj_lastCreatedGroup
endfunction
//This leaks a lot accually is you create say 12 units!
//Look at all those locations, and a group
 
Status
Not open for further replies.
Top