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

Leak/Bug Question

Status
Not open for further replies.
Level 7
Joined
Jul 20, 2009
Messages
295
Hello,

Would removing a buff or an ability from a unit even if the unit doesn't have it cause any problems or leaks?
Same goes with Setting variables to something that they already are.
Again, with removing units that may or may not exist.
 
Level 7
Joined
Jul 20, 2009
Messages
295
Will be hard to explain, but here it goes:

This is because I've made all my spells via triggers, adding abilities, removing them and removing their buffs all via triggers.
What I've done is that, each of these spells are multi levelled, thus the abilities to be added to the units are different and via variables, I've set the variables to the abilities according to the lvl of the spell.
Then when the spell is recast, I did a checker whether the unit has the ability/buff or not and now since u said it doesn't matter, i'll just remove this checker and always keep removing even if the unit did not have the ability/buff.

Also, when the spell is cast, I create a dummy (unit) and set it to die after a period of time. (Duration of buff)
So I got to remove this unit and create a new one once spell is recasted.
 
Level 7
Joined
Jul 20, 2009
Messages
295
What I'm doing is as follows:

Before:
When a unit casts a spell,
1) Check if buff exists or unit exists
True - Remove everything that was created (units) and/or given (abilities)
False - (blank)
2) Create + set variables

Now:
When a unit casts a spell,
1) Remove everything that was created (units) and/or given (abilities)
2) Create + set variables

Though, in 'Now', if this spell is casted for the first time or after buff wears off, the game will try to remove something that doesn't exist and remove abilities from units even though the units don't have them.
All I was asking whether this checker is useful or just waste of time+memory to set up.
 
Level 30
Joined
Nov 29, 2012
Messages
6,637
I do like the before because it is more specific and has this good restrictions that if the unit has this specific buff, remove it and such.

Now, it looks quite not specific and might cause some leaks. And if you are trying to remove all buffs that means buffs too that is not related to the spell is also removed which is bad.
 
Level 7
Joined
Jul 20, 2009
Messages
295
I do like the before because it is more specific and has this good restrictions that if the unit has this specific buff, remove it and such.

Now, it looks quite not specific and might cause some leaks. And if you are trying to remove all buffs that means buffs too that is not related to the spell is also removed which is bad.

Hehe,
I'll be more specific
  • Dia Spell
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Ability being cast) Equal to Dia [Hero Spell]
          • (Ability being cast) Equal to Dia 2+3 [Hero Spell]
    • Actions
      • 1) Remove everything that was created (units) and/or given (abilities)
      • Unit - Remove Spells_DiaDummy[(Custom value of (Target unit of ability being cast))] from the game <== DummyUnit
      • Unit - Remove Spells_DiaAbility_Passive[(Custom value of (Target unit of ability being cast))] from (Target unit of ability being cast) <== Ability that gives Buff
      • Unit - Remove Spells_DiaAbility_Unit[(Custom value of (Target unit of ability being cast))] from (Target unit of ability being cast) <== Ability decreases defense
      • Unit - Remove Spells_DiaBuff[(Custom value of (Target unit of ability being cast))] buff from (Target unit of ability being cast) <== To make buff be removed instantly
      • 2) Create + set variables
      • Unit - Add Dia [Unit] to (Target unit of ability being cast)
      • Set Spells_DiaAbility_Unit[(Custom value of (Target unit of ability being cast))] = Dia [Unit]
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Dia [Hero Spell]
        • Then - Actions
          • Unit - Set level of Dia [Unit] for (Target unit of ability being cast) to 1
          • Unit - Add Dia [Passive] to (Target unit of ability being cast)
          • Set Spells_DiaAbility_Passive[(Custom value of (Target unit of ability being cast))] = Dia [Passive]
          • Set Spells_DiaBuff[(Custom value of (Target unit of ability being cast))] = Dia
          • Set Spells_DiaDMG[(Custom value of (Target unit of ability being cast))] = 1.00
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Level of (Ability being cast) for (Triggering unit)) Equal to 1
            • Then - Actions
              • Unit - Set level of Dia [Unit] for (Target unit of ability being cast) to 2
              • Unit - Add Dia II [Passive] to (Target unit of ability being cast)
              • Set Spells_DiaAbility_Passive[(Custom value of (Target unit of ability being cast))] = Dia II [Passive]
              • Set Spells_DiaBuff[(Custom value of (Target unit of ability being cast))] = Dia II
              • Set Spells_DiaDMG[(Custom value of (Target unit of ability being cast))] = 2.00
            • Else - Actions
              • Unit - Set level of Dia [Unit] for (Target unit of ability being cast) to 3
              • Unit - Add Dia III [Passive] to (Target unit of ability being cast)
              • Set Spells_DiaAbility_Passive[(Custom value of (Target unit of ability being cast))] = Dia III [Passive]
              • Set Spells_DiaBuff[(Custom value of (Target unit of ability being cast))] = Dia III
              • Set Spells_DiaDMG[(Custom value of (Target unit of ability being cast))] = 3.00
      • Set TempLocation = (Position of (Target unit of ability being cast))
      • Unit - Create 1 Faerie Dragon [Dia] for (Owner of (Triggering unit)) at TempLocation facing Default building facing degrees
      • Set Spells_DiaDummy[(Custom value of (Target unit of ability being cast))] = (Last created unit)
      • Unit - Add a 3.00 second Generic expiration timer to (Last created unit)
      • Unit - Set the custom value of (Last created unit) to (Custom value of (Target unit of ability being cast))
      • Set Spells_DiaTimer[(Custom value of (Target unit of ability being cast))] = 0.00
      • Custom script: call RemoveLocation(udg_TempLocation)
Does this leak?
 
Removing an ability that a unit doesn't have is fine. I assume the function already does internal checks for that anyway, seeing as the native counterpart returns whether the ability was successfully removed:
JASS:
native UnitRemoveAbility            takes unit whichUnit, integer abilityId returns boolean

You shouldn't have anything to worry about.
 
Status
Not open for further replies.
Top