• 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.

Point leak removal doesn't work, can't figure out why.

Status
Not open for further replies.
Level 3
Joined
Mar 9, 2016
Messages
45
Hello. I have a passive ability that adds 1 strength to the unit that has it every time it has moved a certain distance (155/140/125/110 yards). To do this i set the variable Competitive_Spirit_Point equal to the position of the unit, then check if the distance between Competitive_Spirit_Point and Competitive_Spirit_Point_2 >= 155/140/125/110, and if it is, I add 1 strength to the unit, then set Competitive_Spirit_Point_2 = Competitive_Spirit_Point. So far so good. But when I try to remove the variable points in order to make the code not leak, it suddenly doesnt work. Here's the triggers:

This is for detecting when a unit learns the skill, so that I can add it to a Unit Group in order to access it later in another trigger.
  • Competitive Spirit
    • Events
      • Unit - A unit Learns a skill
    • Conditions
      • ((Triggering unit) has buff Competitive Spirit ) Equal to True
    • Actions
      • Set Competitive_Spirit_Unit = (Triggering unit)
      • Set Competitive_Spirit_Index = (Custom value of Competitive_Spirit_Unit)
      • Set Competitive_Spirit_Distance[Competitive_Spirit_Index] = (170.00 - (15.00 x (Real((Level of Competitive Spirit (Bartholomew) for Competitive_Spirit_Unit)))))
      • Set Competitive_Spirit_Point_2[Competitive_Spirit_Index] = (Position of Competitive_Spirit_Unit)
      • Unit Group - Add Competitive_Spirit_Unit to Competitive_Spirit_Group
      • Trigger - Turn on Competitive Spirit Loop <gen>
      • Trigger - Turn on Competitive Spirit Dummy Dies <gen>
This is the trigger that's adding the strength to the unit
  • Competitive Spirit Loop
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Competitive_Spirit_Group and do (Actions)
        • Loop - Actions
          • Set Competitive_Spirit_Unit = (Picked unit)
          • Set Competitive_Spirit_Index = (Custom value of Competitive_Spirit_Unit)
          • Set Competitive_Spirit_Point = (Position of Competitive_Spirit_Unit)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Distance between Competitive_Spirit_Point and Competitive_Spirit_Point_2[Competitive_Spirit_Index]) Greater than Competitive_Spirit_Distance[Competitive_Spirit_Index]
            • Then - Actions
              • Special Effect - Create a special effect attached to the origin of Competitive_Spirit_Unit using Abilities\Spells\Human\Feedback\SpellBreakerAttack.mdl
              • Special Effect - Destroy (Last created special effect)
              • Set Competitive_Spirit_Point_2[Competitive_Spirit_Index] = (Position of Competitive_Spirit_Unit)
              • Hero - Modify Strength of Competitive_Spirit_Unit: Add 1
              • Unit - Create 1 Dummy 6 for (Owner of Competitive_Spirit_Unit) at Competitive_Spirit_Point facing Default building facing degrees
              • Unit - Add a 10.00 second Generic expiration timer to (Last created unit)
              • Unit Group - Add (Last created unit) to Competitive_Spirit_Group_2
              • Set Competitive_Spirit_Unit_2[(Custom value of (Last created unit))] = Competitive_Spirit_Unit
            • Else - Actions
Just for context, so that you get a better idea of what the spell does, this is the trigger that removes the strength from the unit, so that the strength gain isnt permanent: (im using a dummy unit and it's life timer to detect when the strength should be removed. Can't think of a better way to do it, but if you can, I'd appriciate such input :) )
  • Competitive Spirit Dummy Dies
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Triggering unit) is in Competitive_Spirit_Group_2) Equal to True
    • Actions
      • Hero - Modify Strength of Competitive_Spirit_Unit_2[(Custom value of (Triggering unit))]: Subtract 1

So what actually happens when I try to remove the leaking points?
Strength gets added to the unit regardless of the distance it has moved from Competitive_Spirit_Point_2, that is, once every 0.03 seconds.

Note: I've tried putting the leak-removal line of code at every line in the trigger i could think of that I imagined would work, but it just doesn't. What am I doing wrong?

THANKS!
 
Level 7
Joined
Oct 19, 2015
Messages
286
You should destroy Competitive_Spirit_Point_2[Competitive_Spirit_Index] before this line, and nowhere else:
  • Set Competitive_Spirit_Point_2[Competitive_Spirit_Index] = (Position of Competitive_Spirit_Unit)
You should destroy Competitive_Spirit_Point at the end of periodic trigger, outside of the if statement.
 
Level 3
Joined
Mar 9, 2016
Messages
45
You should destroy Competitive_Spirit_Point_2[Competitive_Spirit_Index] before this line, and nowhere else:
  • Set Competitive_Spirit_Point_2[Competitive_Spirit_Index] = (Position of Competitive_Spirit_Unit)
You should destroy Competitive_Spirit_Point at the end of periodic trigger, outside of the if statement.
Works like a charm! :D Thanks a bunch. +rep !!

Would you mind explaining why it doesnt work to remove Competitive_Spirit_Point just before this line thou?:
  • Set Competitive_Spirit_Point = (Position of Competitive_Spirit_Unit)
Would be grateful
 
Level 7
Joined
Oct 19, 2015
Messages
286
I made a mistake, I forgot that you were looping through the group, you should remove the location at the end of the loop, not at the end of the trigger. It should also work if you remove it where you suggested, does it not work?
 
Level 3
Joined
Mar 9, 2016
Messages
45
I made a mistake, I forgot that you were looping through the group, you should remove the location at the end of the loop, not at the end of the trigger. It should also work if you remove it where you suggested, does it not work?

Lol I must have misunderstood you, becasue I DID put the line in the end of the loop, not at the end of the trigger; like this:
  • Competitive Spirit Loop
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Competitive_Spirit_Group and do (Actions)
        • Loop - Actions
          • Set Competitive_Spirit_Unit = (Picked unit)
          • Set Competitive_Spirit_Index = (Custom value of Competitive_Spirit_Unit)
          • Set Competitive_Spirit_Point = (Position of Competitive_Spirit_Unit)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Distance between Competitive_Spirit_Point and Competitive_Spirit_Point_2[Competitive_Spirit_Index]) Greater than Competitive_Spirit_Distance[Competitive_Spirit_Index]
            • Then - Actions
              • Special Effect - Create a special effect attached to the origin of Competitive_Spirit_Unit using Abilities\Spells\Human\Feedback\SpellBreakerAttack.mdl
              • Special Effect - Destroy (Last created special effect)
              • Custom script: call RemoveLocation(udg_Competitive_Spirit_Point_2[udg_Competitive_Spirit_Index])
              • Set Competitive_Spirit_Point_2[Competitive_Spirit_Index] = (Position of Competitive_Spirit_Unit)
              • Hero - Modify Strength of Competitive_Spirit_Unit: Add 1
              • Unit - Create 1 Dummy 6 for (Owner of Competitive_Spirit_Unit) at Competitive_Spirit_Point facing Default building facing degrees
              • Unit - Add a 10.00 second Generic expiration timer to (Last created unit)
              • Unit Group - Add (Last created unit) to Competitive_Spirit_Group_2
              • Set Competitive_Spirit_Unit_2[(Custom value of (Last created unit))] = Competitive_Spirit_Unit
            • Else - Actions
          • Custom script: call RemoveLocation(udg_Competitive_Spirit_Point)
So we got lucky there I guess :D

And apparently it also works if I put it where I suggested... I dunno why this always happens to me... As soon as i ask for help, everything I tried before that didn't seem to work suddenly does work :D But I guess I kept putting the removal of Competitive_Spirit_Point_2[x] before the condition or after this line or smth:
  • Set Competitive_Spirit_Point_2[Competitive_Spirit_Index] = (Position of Competitive_Spirit_Unit)
anyways, thanks for the help again!

Edit: the only reason I could think of as to why it wasnt working before I made this thread was that the call RemoveLocation function somehow destroyed the variable itself, so I couldnt access it anymore. But ofc I know thats bogus because it doesnt make sense and since I'm removing leaks this way in all my other triggers, so... yeah
 
Level 3
Joined
Mar 9, 2016
Messages
45
I'm not sure if this is the full trigger, but will the distance between Competitive_Spirit_Point and Spirit_Point_2 evidently reach Spirit_Distance? If not, you have a problem of Point_2 not being removed for it is only removed if that condition is met.

Are you asking if the distance between Point_1 and Point_2 is guaranteed to reach Competitive_Spirit_Distance at some point? It is not, but that would only result in the leak of one point during the course of a whole game, since Point_2 is only set to a value when a hero learns the spell and when the distance between Point_1 and Point_2 is >= Spirit_Distance.

Did I understand your question correctly though?

Either way, Point_2 is only assigned a (new)value when the condition (distance between Point_1 and Point_2 >= Spirit_Distance) is met, so shouldnt it be fine that the point is only cleaned up when that same condition is met? Seems like a 1:1 ratio of point-creating and point-removing to me in all cases :)
 
You understood the question. I dont know how your project will work, I just assume every trigger I see has the potential to be ran more than once.

Under the assumption that the trigger you provided is everything, think about a scenario where the condition is not met. This means that Point_2 still holds the position of the unit at the moment of learning the skill since you only remove it if the condition is met. Keep in mind that doesn't necessarily mean it leaks since you can still reference it when you need to. However, the moment this trigger fires again, the original Point_2 will be lost, creating a leak.
 
Level 7
Joined
Oct 19, 2015
Messages
286
It's true, the code will leak a point whenever the skill is leveled up. Judging by the code it looks like it is meant to be a multi level skill, so this can happen. It's not the end of the world but technically it is a leak.
 
Status
Not open for further replies.
Top