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

[General] Removing nothing

Status
Not open for further replies.
Level 3
Joined
Sep 21, 2013
Messages
36
Is there any performance loss when you remove non-existent abilities from unit, or when removing unit from unit group in which he is not consists?
Thanks in advance and +rep to everyone.
 
Level 15
Joined
Aug 7, 2013
Messages
1,338
Yes it doesn't do anything bad. I suppose you're doing this because it makes your code more general? As in whatever triggers you adding the ability could be a unit that already has it
 
Level 19
Joined
Mar 18, 2012
Messages
1,716
Nothing bad will happen as everyone stated already. :)

The UnitAddAbility/UnitRemoveAbility natives return a boolean.

If you add an ability to a unit which that unit already has --> nothing happens and the function will return false.
If you remove an ability from a unit which that unit doesn't have --> nothing happens and the function will return false.

How to we use that to our benefit:
JASS:
if UnitAddAbility(unit, ability) then
    call KillUnit(unit)
else
    //
endif
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
In these specific case, it does not matter. It takes a bit of performance for the function call, of course. However, you should not assume that every function is protected against each kind of invalid input. For example trying to destroy already destroyed lightnings regularly induces fatal error despair.
 
Status
Not open for further replies.
Top