Are Unremoved Variables considered Leaks?

RailKill

New Member
Reaction score
0
I would like to ask for some help/information on my trigger. So, I have a trigger like this...


Trigger:
  • Shoot the SMG
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Fire Uzi
    • Actions
      • Set SMGFireStart[(Player number of (Owner of (Triggering unit)))] = (Position of (Triggering unit))
      • Set Point = (Target point of ability being cast)
      • Set SMGFireEnd[(Player number of (Owner of (Triggering unit)))] = (SMGFireStart[(Player number of (Triggering player))] offset by 900.00 towards (Angle from SMGFireStart[(Player number of (Triggering player))] to Point) degrees)
      • Custom script: call RemoveLocation(udg_Point)
      • Set SMGFireEnd2[(Player number of (Triggering player))] = (SMGFireStart[(Player number of (Triggering player))] offset by 900.00 towards ((Angle from SMGFireStart[(Player number of (Triggering player))] to SMGFireEnd[(Player number of (Triggering player))]) + (Random real number between (0.00 - AccuracyRifles[(Playe
      • Set SMGFireEnd3[(Player number of (Triggering player))] = (SMGFireStart[(Player number of (Triggering player))] offset by 900.00 towards ((Angle from SMGFireStart[(Player number of (Triggering player))] to SMGFireEnd[(Player number of (Triggering player))]) + (Random real number between (0.00 - AccuracyRifles[(Playe
      • Set SMGFireEnd4[(Player number of (Triggering player))] = (SMGFireStart[(Player number of (Triggering player))] offset by 900.00 towards ((Angle from SMGFireStart[(Player number of (Triggering player))] to SMGFireEnd[(Player number of (Triggering player))]) + (Random real number between (0.00 - AccuracyRifles[(Playe
      • Set SMGFireEnd5[(Player number of (Triggering player))] = (SMGFireStart[(Player number of (Triggering player))] offset by 900.00 towards ((Angle from SMGFireStart[(Player number of (Triggering player))] to SMGFireEnd[(Player number of (Triggering player))]) - (Random real number between (0.00 - AccuracyRifles[(Playe





Basically the trigger I'm doing here is to set the Points to create the bullet. There are 5 bullets that I am going to create. It is the main attack skill, so it will trigger over and over again almost all of the time.




So my question is, I only removed the Point variable using "call RemoveLocation(udg_Point)", but I did not remove the SMGFireStart and SMGFireEnd variables. Do these unremoved stuff leak? Do note that this trigger is going to run over and over again.


Also, does any part of the trigger leak? Thanks in advance.
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
for the sake of god use an integer variable to store (Player number of (Owner of (Triggering unit))) and use that instead in your arrays. one cannot really read this stuff.

and back to topic, of course they leak. re-setting a point / rect / unit group / (plenty more) variable always causes leak if the last value hasnt been removed yet.
 

Cookiemaster

New Member
Reaction score
36
The above poster (Accname) makes a good point about your variable-usage. It is better if you use arrays.

The problem with that is though, you are already using arrays! And, judging by your code, 12 (16?) fields are used. One for each player.


Here's some real magic, let's say you could give TWO numbers to choose a field in the array? E.g. int[playerid][number].

Warcraft 3 does not support it, but we CAN SIMULATE this.
Since one of the two fields has a fixed maximum on it, (Let's just assume 16 for the players here. 12 players + neutral hostile/passive/rescue/extra.) all we have to do is multiply the OTHER number by 16.
How does it work? Simple.
0~15 are the variables used for number 0, 16~31 are the variables for number 1, 32~47 ETCETERA. With this method, you "fake" a double array by multiplying a fixed number, the max-size of input-1, by input-2, and then add input-1 to it. Ta-da.


BUT THIS IS NOT REALLY THE THING YOU'RE ASKING FOR SO LET'S GET TO BUSINESS THAT IS MORE TO YOUR CONCERN SHALL WE?

Yes, those variables, every single one leaks. You have cleared one leak though, which is udg_Point. Now, judging from your code, you're probably going to use those variables for something, (I guess over time?) and it is possible that it's not after a set of actions without pauses between them. Which means you can't just destroy them at the end of the trigger now! (oh no!)

What we CAN do however, is destroy the variables at the BEGINNING of the trigger.
The reason variables such as Points, special effects and unit groups leak is because they're POINTERS to objects in warcraft 3.

Simple example to explain this:

JASS:
set point1 = Center of (Playable Map Area)
set point2 = point1
call RemoveLocation(point1)


This would make point1 "null" (or "no point").
What it also does is make point2 "null"! How is this possible?!

It's because both point1 and point 2 were both POINTERS to the same point-object that you created!

You might be wondering what this has to do with your problem.
The reason your variables leak is because the variable points to a different object in warcraft 3, while the old point-object still exists. To prevent leaking, you must destroy the point first, before assigning it to a newly-created point.

Generally, this is done in the same trigger/function as you create them.
This is because the points are not used at all outside that function/trigger, but in your case, it just might be so!

The solution to this would be to destroy any point the variable holds before putting a new one in it. So just call a DestroyLocation() on all your point-variables at the start in your trigger/function.

In case you're also setting these variables somewhere else, remember to destroy what they hold before setting/overwriting them.
 

RailKill

New Member
Reaction score
0
Thanks Accname for the clear answer and Cookiemonster for the detailed explanation. Yeah, offtopic, the double array is a better and easier way of doing it...guess I just didn't thought of it at the time! =P



Ontopic,

Yes, the variables, SMGFireStart and the other SMGFireEnd variables are used in another trigger, which are Periodic Events to move the bullet from SMGFireStart to SMGFireEnd. Since I wanted to make the end points vary (to simulate inaccuracy), I made 5 end points. Since it is being used in another trigger over a period of time, I guess the variables cannot be removed until the trigger is done moving the bullets. Here is the trigger:


Trigger:
  • Move Bullet SMG 1 P1
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (SMGBullet1[1] is alive) Equal to True
        • Then - Actions
          • Set Point2 = (Position of SMGBullet1[1])
          • Set Point = (Point2 offset by 90.00 towards (Angle from Point2 to SMGFireEnd[1]) degrees)
          • Unit - Move SMGBullet1[1] instantly to Point
          • Custom script: call RemoveLocation(udg_Point)
          • Custom script: call RemoveLocation(udg_Point2)
        • Else - Actions
          • Unit - Kill SMGBullet1[1]
          • Trigger - Turn off (This trigger)




OK, I added an expiration timer (time is based on distance travelled) for the bullet unit after the creation of the bullet beforehand. The above is the trigger to move the bullet. The thing is, I can use "call RemoveLocation(udg_SMGFireEnd[1])" and so on under the "ELSE - ACTIONS". It would work, right?

But there is a period of time before the variables are removed. So, if the unit fires rapidly (before the bullets from the previous shot die), then the variables are assigned again BEFORE they are removed. This creates leaks and the bullet will not travel properly in the 2nd shot, because the variables are then removed by that time (which is when the bullets from the previous shot die).


Is there any way to make sure they are removed? Maybe using a variable with array would help?

EDIT: Other than adding a longer cooldown to the ability so that the bullets can die before the unit fires again. I wouldn't prefer to use this way because weapons that fire fast are epic and players like them...
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
i would say give your bullets the "rally" ability.
units with the rally ability can set a rally point to either be a point or a unit /destructible.
then you can set the bullets rally point to the end point and make it travel to its rally point.

besides that you could always use hashtables to store all of that data as well but rally points are better in my opinion.
 

RailKill

New Member
Reaction score
0
Thanks Accname, I'll type out what I understand and please correct me if I'm wrong.

So I'll add the "Rally" ability for the bullets in Object Editor in order for them to set a Rally Point. In this case, all I had to do is to add one extra Action in the trigger from my first post (named Shoot the SMG), which is, "Unit - Set Rally-Point for (Last Created Unit) to (SMGFireEnd)" (for the rest of the 5 endpoints as well). Am I correct so far?


Then, in the "Move Bullet" trigger shown in my 2nd post, I would move the bullets from SMGFireStart to "Rally-Point of SMGBullet as Point", right?



Wouldn't the rally point be a leak as well? Sorry if the question is weird/dumb, I'm not really good at triggers...yet. Thanks! =P


EDIT: Okay, I failed. I added the "Rally" ability to the bullet in Object Editor. I used "Unit - Set Rally-Point for (Last Created Unit) to (SMGFireEnd)" for the respective bullets in Shoot the SMG trigger, and put in a Point3 = Rally-Point of Bullet as Point and removed Point3 after moving the bullet in Move Bullet trigger, but it didn't work.

I tried adding a Wait in-between so that maybe the unit needs time to set the rally-point, but it did not work. I also tried NOT removing any variables (the end points and the rally point variables) but it did not work as well.

This would mean that the Rally-Point was not assigned at all, right? Please help!
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top