• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

HOW to make Distance-storing not to leak?

Status
Not open for further replies.
Level 3
Joined
Mar 30, 2013
Messages
22
Hey guys, i wanna make a unit stop moving after 600 distance for my roundbased map.

Trigger as far as follows:

  • Distanz
    • Events
      • Time - Every 0.10 seconds of game time
    • Conditions
    • Actions
      • Set Point1 = Point2
      • Set Point2 = (Position of Unit)
      • Set Real1 = (Real1 + (Distance between Point1 and Point2))
      • Custom script: call RemoveLocation(udg_Poin1)
Guess this keeps leaking, since i can only remove one location?
I need to store the second one (the newly defined "Point2") for the following interval of the Trigger. Any way around that?
 
do it this way and dont forget to null handles after destroying.

  • Distanz
    • Events
      • Time - Every 0.10 seconds of game time
    • Conditions
    • Actions
      • Set Point1 = Point2
      • Custom script: call RemoveLocation(udg_Poin2)
      • Custom script: set Point2 = null
      • Set Point2 = (Position of Unit)
      • Set Real1 = (Real1 + (Distance between Point1 and Point2))
      • Custom script: call RemoveLocation(udg_Poin1)
      • Custom script: set Point1 = null
 
Level 3
Joined
Mar 30, 2013
Messages
22
Error: Variable name expected ....?
Isnt working, none of both versions, the first one causes the units to stop instantly when they are picked, the second one causes error as told...
 
Level 3
Joined
Mar 30, 2013
Messages
22
  • VorbereitungDist
    • Events
    • Conditions
    • Actions
      • Set Point2 = (Position of Unit)
      • Trigger - Turn on Distanz <gen>

this one is called by another one, setting "Distanz" to 0 and chosing the unit... not much to do with this problem i guess...

  • Stopwhen600
    • Events
      • Game - Distanz becomes >= 600.00
    • Conditions
    • Actions
      • Unit - Set Unit movement speed to 0.00
 
it was my mistake thats y.
heres the fix sry about that

  • Distanz
    • Events
      • Time - Every 0.10 seconds of game time
    • Conditions
    • Actions
      • Set Point1 = Point2
      • Custom script: call RemoveLocation(udg_Poin2)
      • Custom script: set udg_Point2 = null
      • Set Point2 = (Position of Unit)
      • Set Real1 = (Real1 + (Distance between Point1 and Point2))
      • Custom script: call RemoveLocation(udg_Poin1)
      • Custom script: set udg_Point1 = null
 
Level 4
Joined
Jan 27, 2010
Messages
133
Your first method doesn't leak. When you do Point1 = Point2, you don't create a new location. You are merely telling Point1 to point at the same location as Point2. (i.e. when you destroy Point1 later, you actually are destroying the old Point2)

i.e. this is perfectly fine (so long as you set up Point2 before first use):

  • Distanz
  • Events
    • Time - Every 0.10 seconds of game time
  • Conditions
  • Actions
    • Set Point1 = Point2
    • Set Point2 = (Position of Unit)
    • Set Real1 = (Real1 + (Distance between Point1 and Point2))
    • Custom script: call RemoveLocation(udg_Poin1)
 
Level 3
Joined
Mar 30, 2013
Messages
22
it was my mistake thats y.
heres the fix sry about that

Aw right, the udg_... should have got that myself, ty!

But!! Its still not working :D when i destroy the variable after the first "set", the Unit simply wont move when the trigger starts, so it seams like it counts much distance between fucked up positions? Not sure...
 
Level 4
Joined
Jan 27, 2010
Messages
133
I think we pretty much established that nulling globals is not really necessary.

he resets point 2 that is were the leak is.
Nope. Object variables are pointers.

Imagine you are dealing with units. What would the following yield?

u1 = u2
KillUnit (u1)
IsUnitAlive(u2)

Just wanted to point out that in your trigger, Point1 is actually pointing to a destroyed location when doing the Distance test (and that's the reason why Jesaja can't get it to work).

You can use the trigger you posted first, Jesaja. It does not leak.
 
Level 3
Joined
Mar 30, 2013
Messages
22
Well what themerion says kinda works, gonna see if it leaks in a few days when playtesting with my friends, thanks to everybody!
 
Level 7
Joined
Jan 22, 2013
Messages
293
Ok everyone!, Watch Closely, Death did it right, Unexpected error is from a typo (he likes to trigger when hes tired, idk why)

it was my mistake thats y.
heres the fix sry about that

  • Distanz
    • Events
      • Time - Every 0.10 seconds of game time
    • Conditions
    • Actions
      • Set Point1 = Point2
      • Custom script: call RemoveLocation(udg_Poin2)
      • Custom script: set udg_Point2 = null
      • Set Point2 = (Position of Unit)
      • Set Real1 = (Real1 + (Distance between Point1 and Point2))
      • Custom script: call RemoveLocation(udg_Poin1)
      • Custom script: set udg_Point1 = null

If you did not see it I will point it out.
  • Custom script: call RemoveLocation(udg_Poin2)
  • Custom script: call RemoveLocation(udg_Poin1)
  • Set Point2
  • Set Point1
He forgot to type T at the end of the removelocations. The fac the did it on both is because he copy/pasted the first one as the second one and just changed the number, hince why he never saw the problem.


Personally I would set the trigger up like this:


  • Distanz
    • Events
      • Time - Every 0.10 seconds of game time
    • Conditions
    • Actions
      • Set Point1 = Point2
      • Set Point2 = (Position of Unit)
      • Set Real1 = (Real1 + (Distance between Point1 and Point2)
      • -------- Truly your always using the Point2 again so there is no point --------
      • -------- in keeping it above this line --------
      • -------- Because Every 0.10 seconds, it will be used again --------
      • Custom script: call RemoveLocation(udg_Point2)
      • Custom script: call RemoveLocation(udg_Point1)
      • Custom script: set udg_Point2 = null
      • Custom script: set udg_Point1 = null


First off @ themerion Your missing something that clearly me and deathismyfriend see.

List of Locations:
Point1
Point2

If I set Point 1 = Two, then now 2 locations are INDIVIDUALLY set, not together.

That is why you can't just remove "Point 1" Because Point 1 is now a Clone of Point 2 (in general terms) Point 2 is Used at the beginning of the trigger, meaning because of it not being Removed and nulled it will overlap and leak the second time of use. Just because it is the same cord's does not mean they are fused into one variable and you only need to remove that single variable now.

Also, Because it goes down this chain, the first time this trigger is used, you need to make sure after the first use it has removed any remains of the Point2, that way when its used again its already reset and ready for use, not reset it during its use again, that is just plain gibberish.

I must approach this rather aggressive in order for you to realize how serious I am about that. Remove it at the end, and if he's trying to reset Point2 from another trigger prior to this triggers use, then he should be setting it not as point2 but as point3, to prevent that problem.

I hope you understand this.
 
Last edited:
Level 4
Joined
Jan 27, 2010
Messages
133
If I set Point 1 = Two, then now 2 locations are INDIVIDUALLY set, not together.

That is why you can't just remove "Point 1" Because Point 1 is now a Clone of Point 2

It is NOT a clone, the variables are POINTERS. (For the third time...)

  • Test
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • Set Point1 = (Point(10.00, -150.00))
      • Set Point2 = Point1
      • Custom script: call RemoveLocation(udg_Point2)
      • Game - Display to (All players) the text: (String((X of Point1)))
I spent some time setting up an understandable test case. This code outputs 0.00. Please try to understand the implications of that before you answer.

First off @ themerion Your missing something that clearly me and deathismyfriend see.
I am quite confident that this is a case of: I see something because I have experience in actual object oriented programming.
 
Last edited:
Level 7
Joined
Jan 22, 2013
Messages
293
It is NOT a clone, the variables are POINTERS. (For the third time...)

  • Test
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • Set Point1 = (Point(10.00, -150.00))
      • Set Point2 = Point1
      • Custom script: call RemoveLocation(udg_Point2)
      • Game - Display to (All players) the text: (String((X of Point1)))
I spent some time setting up an understandable test case. This code outputs 0.00. Please try to understand the implications of that before you answer.


I am quite confident that this is a case of: I see something because I have experience in actual object oriented programming.

do you have a test map like Maker did for you? To prove this at a large scale?
 
Level 22
Joined
Sep 24, 2005
Messages
4,821
Scaling is irrelevant, themerion tested for the management of handle type variables, which is deterministic. Whatever the scale, the results of themerion's test will still hold true.

Also, jass, while structured, does not natively support object oriented programming(?).
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
You guys want solid evidence if themerion is correct, right ?
To say that they refer to POINTER not setting handles individually, right ?
Try this;
  • Actions
    • Set Point1 = (Center of (Playable map area))
    • Set Point2 = Point1
    • Set Point3 = Point2
    • Set Point4 = Point3
    • Set Point5 = Point4
    • Custom script: call RemoveLocation(udg_Point1)
    • Special Effect - Create a special effect at Point5 using Abilities\Spells\Human\ThunderClap\ThunderClapCaster.mdl
    • Special Effect - Destroy (Last created special effect)
When you do this, there will be no SFX will appear, WHY ?
Because you have removed the origin pointer, making it loses its pointer, got it ?

This applies to all pointers, if you do this, there still no SFX being created'
  • Actions
    • Set Point1 = (Center of (Playable map area))
    • Set Point2 = Point1
    • Set Point3 = Point2
    • Set Point4 = Point3
    • Set Point5 = Point4
    • Custom script: call RemoveLocation(udg_Point5)
    • Special Effect - Create a special effect at Point1 using Abilities\Spells\Human\ThunderClap\ThunderClapCaster.mdl
    • Special Effect - Destroy (Last created special effect)
Because all variable refers to the same POINTER.
So basically if you remove just one from its pointer, all will lose its pointer, meaning that leak is cleaned.

You have to understand Object-oriented Programming first to debate about this (just basic concept, that's it).

There are 2 types of copy, deep copy and shallow copy.


BUT, when we deal with non-handle variable such as these;
  • Actions
    • Set i1 = 2
    • Set i2 = i1
    • Set i3 = i2
    • Set i1 = 0
    • Game - Display to (All players) the text: (String(i3))
The display value would still be 2, because these are not pointer, they are just taking up values.

The pointer-case is called as Shallow Copy whereas for the Integer-case is called as Deep Copy.
 
Last edited:
Status
Not open for further replies.
Top