• 🏆 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 it leak ?

Status
Not open for further replies.
Does it leak ? (SOLVED)

Hello !

What this simple trigger does is to locate the "center of gravity" of a unit group, but I may have a slight leaking problem (Maybe not !).
The original test trigger is this one (it moves a "praetorian" unit in the center of gravity of a group of "legionaries") :


  • Test Center of Gravity of Regiment
    • Events
      • Joueur - Joueur 1 (Rouge) skips a cinematic sequence
    • Conditions
    • Actions
      • Set UNITGROUP = (Units in TESTREGIMENT <gen> matching ((Unit-type of (Matching unit)) Egal Ã* Legionary))
      • Set UNIT = Pretorian 0122 <gen>
      • Set INTEGER = 0
      • Custom script: set bj_wantDestroyGroup=true
      • Unit Group - Pick every unit in UNITGROUP and do (Actions)
        • Boucle - Actions
          • Set INTEGER = (INTEGER + 1)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • INTEGER superior or equal to 2
            • Then - Actions
              • Set POINT = (Position of (Picked unit))
              • Set POINT2 = POSITIONREGIMENT
              • Custom script: call RemoveLocation(udg_POSITIONREGIMENT)
              • Set POSITIONREGIMENT = (POINT2 offset by ((Distance between POINT2 and POINT) / (Real(INTEGER))) towards (Angle from POINT2 to POINT) degrees)
              • Custom script: call RemoveLocation(udg_POINT)
              • Custom script: call RemoveLocation(udg_POINT2)
            • Else - Actions
              • Set POSITIONREGIMENT = (Position of (Picked unit))
      • Unit - Move UNIT instantly to POSITIONREGIMENT
      • Custom script: call RemoveLocation(udg_POSITIONREGIMENT)


So what I think is that when I created this POINT2 = POSITIONREGIMENT, it actually doesn't create a new point, so when I remove POSITIONREGIMENT, POINT2 is also removed, so I removed the removal and the trigger works nicely !
But just to be sure, does removing POINT2 removes the point created when POSITIONREGIMENT was set ? (does this trigger leak ?) :


  • Test Center of Gravity of Regiment
    • Events
      • Joueur - Joueur 1 (Rouge) skips a cinematic sequence
    • Conditions
    • Actions
      • Set UNITGROUP = (Units in TESTREGIMENT <gen> matching ((Unit-type of (Matching unit)) Egal Ã* Legionary))
      • Set UNIT = Pretorian 0122 <gen>
      • Set INTEGER = 0
      • Custom script: set bj_wantDestroyGroup=true
      • Unit Group - Pick every unit in UNITGROUP and do (Actions)
        • Boucle - Actions
          • Set INTEGER = (INTEGER + 1)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • INTEGER superior or equal to 2
            • Then - Actions
              • Set POINT = (Position of (Picked unit))
              • Set POINT2 = POSITIONREGIMENT
              • Set POSITIONREGIMENT = (POINT2 offset by ((Distance between POINT2 and POINT) / (Real(INTEGER))) towards (Angle from POINT2 to POINT) degrees)
              • Custom script: call RemoveLocation(udg_POINT)
              • Custom script: call RemoveLocation(udg_POINT2)
            • Else - Actions
              • Set POSITIONREGIMENT = (Position of (Picked unit))
      • Unit - Move UNIT instantly to POSITIONREGIMENT
      • Custom script: call RemoveLocation(udg_POSITIONREGIMENT)


Thanks for checking the forums ! and sorry for the remaining french bit in the trigger ;)
 
Last edited:
Level 37
Joined
Jul 22, 2015
Messages
3,485
set bj_wantDestroyGroup=true only works when you use it before you create a unit group. You created your group at the Set UNITGROUP line, which is way before it. The proper way of destroying it if you create groups the way you did is to add call DestroyGroup(udg_UNITGROUP) after your unit group function.

That last trigger also definitely leaks some points. Imagine a situation like this:
  1. INTEGER is 1 -> Not greater than or equal to 2, Set POSITIONREGIMENT = (Position of (Picked unit))
  2. Integer is 2 -> Greater than or equal to 2, POSITIONREGIMENT will overwrite (^leak occurs here since you lose reference of this)

The only time POSITIONREGIMENT doesn't leak is if only one unit is enumerated in your unit group loop, or if there are more units, the last instance of POSITIONREGIMENT.

On a side note, what's the point of storing the location of the first unit enumerated by the unit group loop if you do nothing with it? Unless of course there is only one unit picked, then that means the Pretorian unit will be moved to that unit's location (but only when one unit is picked from the entire function).
 
set bj_wantDestroyGroup=true only works when you use it before you create a unit group. You created your group at the Set UNITGROUP line, which is way before it. The proper way of destroying it if you create groups the way you did is to add call DestroyGroup(udg_UNITGROUP) after your unit group function.
Well, actually, the trigger you see is just some test and wont be used as is. The real one should have a UNITGROUP already set before, and there will be picked the units from this group matching the fact that they're alive ;)

That last trigger also definitely leaks some points. Imagine a situation like this:
INTEGER is 1 -> Not greater than or equal to 2, Set POSITIONREGIMENT = (Position of (Picked unit))
Integer is 2 -> Greater than or equal to 2, POSITIONREGIMENT will overwrite (^leak occurs here since you lose reference of this)
Are you sure I lose the reference of it since I set POINT2=POSITIONREGIMENT and then destroy this POINT2?? (that is the whole point of this thread; I wasn't sure that POINT2 would link at the same "Item" as the previsously made POSITIONREGIMENT)

On a side note, what's the point of storing the location of the first unit enumerated by the unit group loop if you do nothing with it?

I do something with it ;) It is stored as POINT2 when INTEGER=2 and used to calculate the second POSITIONREGIMENT : exactly between the 2 first units picked
 
Level 37
Joined
Jul 22, 2015
Messages
3,485
Are you sure I lose the reference of it since I set POINT2=POSITIONREGIMENT and then destroy this POINT2?? (that is the whole point of this thread; I wasn't sure that POINT2 would link at the same "Item" as the previsously made POSITIONREGIMENT)

Ahh my mistake. I didn't see that :) then yes, everything is fine (excluding that UNITGROUP).
 
Level 3
Joined
Dec 31, 2003
Messages
42
Are you sure I lose the reference of it since I set POINT2=POSITIONREGIMENT and then destroy this POINT2?? (that is the whole point of this thread; I wasn't sure that POINT2 would link at the same "Item" as the previsously made POSITIONREGIMENT)

Perhaps this is the explanation you're after: You can think of a location as an object, like a unit or item. Only it holds less information, mainly the (x, y)-coordinates. The variable only points to the object. If you remove the object itself, the variable will point to a null object.

You can test it yourself quite easily if you store a location in a variable, print eg the x-coordinate, then remove the location and print the x-coordinate again.
 
Perhaps this is the explanation you're after: You can think of a location as an object, like a unit or item. Only it holds less information, mainly the (x, y)-coordinates. The variable only points to the object. If you remove the object itself, the variable will point to a null object.
Yep ! that's what I wanted confirmed by asking in the thread :)
 
Status
Not open for further replies.
Top