How to Give a unit the ability to fly

Unit Flying Ability
(The Right Way)

Table of Contents

Introduction

This is quite a simple tutorial. I made it quite short and straight to the point because there's
not much to say. Basically, what we've been doing to give units the ability to fly is wrong.
Some Jass coders already know this, but most GUI coders don't.

The Problem

Most GUI coders do this to give a unit the ability to fly:

  • Unit - Add Crow Form to SomeUnit
  • Unit - Remove Crow Form from SomeUnit
This is wrong..
Why? Because:

Assume you have a unit that has the ability 'Arav' (Raven Form/Crow Form).
Now, if we were to add the ability to this unit, the function would fail this attempt and
UnitAddAbility will return false. After we remove the ability (In the second
line of the GUI method), the original 'Arav' ability will be removed.

We can conclude that the GUI method is unsafe, bug-prone and WRONG!

The Solution

As I mentioned before, UnitAddAbility will return false if the ability adding has failed.
We can take advantage of this to write a snippet that attempts to add the ability, checks if the ability
was added, and if it was, the ability will be removed. Luckily, we can do this with no overhead at all.

Or, you can simply check the level of the ability. If it's 0, add and remove the abilities.
If not, do nothing. (No! Don't use the action 'Do Nothing' because all it does is slow you down!)

  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • (Level of Crow Form for Unit) Equal to 0
    • Then - Actions
      • Unit - Add Crow Form to Unit
      • Unit - Remove Crow Form from Unit
    • Else - Actions
But, I'd strongly recommend to Always use this faster, safer and better method instead:

  • Custom script: if UnitAddAbility(udg_Unit,'Amrf') then
  • Custom script: call UnitRemoveAbility(udg_Unit,'Amrf')
  • Custom script: endif
Those three lines would attempt to add the ability to the unit.
If the condition (UnitAddAbility) returns false, the ability won't be removed. If it returns true,
the ability will be removed.

Tips

  • If you're making a map, you can totally avoid these checks by
    creating an alternate crow form ability that you'll never use. (Credits to noob)
  • Some people use 'Amrf', some use 'Arav', there's pretty much
    no difference. If you're a GUIer and you're not sure what those are,
    they're codes that correspond to each ability.
  • This method should be applied for ALL abilities.

Wrap-Up

That's pretty much it. I hope you like this short but informing tutorial and I hope you
won't be making the mistake of blindly adding and removing unit abilities again. ;)
Thank you for reading.

~Magtheridon96
 
Last edited:
Level 15
Joined
Aug 7, 2009
Messages
1,407
Yea, nice tutorial for GUI users - length is really not something that matters, but usefulness. (I used to use the "bad method" too when I was a beginner [GUI] triggerer :p Sad story)

However I still consider the simple AutoFly snippet more easy and more useful :)
 
Level 15
Joined
Aug 7, 2009
Messages
1,407
  • Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Level of Crow Form for (Triggering unit)) Equal to 0
      • Then - Actions
        • Unit - Add Crow Form to (Triggering unit)
      • Else - Actions
There you go. But that custom script is faster, it's only 3 lines of JASS script, and you know what it does. But obvisouly you have to decide which method you wanna use.
 
You're probably right :p
I dont have the WE right now, so I'll just guess what functions are called xD

I think this:

  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • (Level of Crow Form for SomeUnit) Equal to 0
    • Then - Actions
      • Unit - Add Crow Form to SomeUnit
      • Unit - Remove Crow Form from SomeUnit
    • Else - Actions
is converted to this:

JASS:
function SomeReaaaaaaaallyLongFunctionName0001001 takes nothing returns boolean
    return not (GetUnitAbilityLevelSwapped('Arav',udg_SomeUnit) == 0) == false
endfunction

function TheActionslol takes nothing returns nothing
    if SomeReaaaaaaaallyLongFunctionName0001001() then
        call UnitAddAbilityBJ('Arav',udg_SomeUnit)
        call UnitRemoveAbilityBJ('Arav',udg_SomeUnit)
    else
    endif
endfunction

Something like that :)
 
Actually, it's a fact that all if conditions look like that, but trigger conditions are an EPIC FAIL XD

JASS:
function Conditions takes nothing returns boolean
    if (not (0==1)) then
        return false
    endif
    return true
endfunction

Actually Blizzard is smart cause they didnt do this:

JASS:
function Conditions takes nothing returns boolean
    if (not (0==1)) then
        return false
    else
        return true
    endif
endfunction

:p lol
 
Actually, it's a fact that all if conditions look like that, but trigger conditions are an EPIC FAIL XD

JASS:
function Conditions takes nothing returns boolean
    if (not (0==1)) then
        return false
    endif
    return true
endfunction

Actually Blizzard is smart cause they didnt do this:

JASS:
function Conditions takes nothing returns boolean
    if (not (0==1)) then
        return false
    else
        return true
    endif
endfunction

:p lol

It doesn't actually take a genius to figure this one out, lol xD
 
W8!
Guys!
I think I know why Blizzard did this:

JASS:
function Conditions takes nothing returns boolean
    if not (something) then
        return false
    endif
    return true
endfunction

And not this:

JASS:
function Conditions takes nothing returns boolean
    if something then
        return true
    endif
    return false
endfunction

It's because a trigger's events will fire quite often, so they wanted to make sure that the actions are NOT supposed to happen first :p
That sux xD

They probably didnt do this:

JASS:
function Conditions takes nothing returns boolean
    return something
endfunction

Because that would make conditions look lame :p
 
Level 24
Joined
Mar 19, 2008
Messages
3,134
Or that they were just lazy enough not to think about the last one.

Lazy? I think they were actually brain storming about condition function.
JASS:
function Conditions takes nothing returns boolean
    if not (something) then
        return false
    endif
    return true
endfunction
Because it's dam hard to create such monster. Would you lose your free time to replace 3 line-script with 6 lines? :p I think they got well paid for that stuff - it explains everything xD
 
No guys ! :D
JASS:
function Conditions takes nothing returns boolean
    if (((something==true)==true)==true) then
        // Check again to make sure :O
        if (((something==true)==true)==true) then
            // Ok now we're sure :P
            return true
        endif
        // HAHA! The Jass Interpreter was wrong >:D
        return false
    endif
    // lol something==false :ogre_hurrhurr:
    return false
endfunction

N00bs :p

Ok, I think we should end this argument xD
 
Last edited:
Level 30
Joined
Jan 31, 2010
Messages
3,583
The heading colors you should use are these:
Color Test
Color Test
Color Test
Color Test
Color Test

As they fit the Hive theme perfectly, and are not pain in the behind to be seen. Alternatively, any font color should be avoided - the one that is used to write everything is good enough - white color is standing out too much.

the title

This is the wrong way of doing it.
Tips should be written in colors that stand out, if any.

The Title

This is the right way of doing it.
Tips should be written in small letters, if any.

For color codes, just quote this message and copy them.
And that orange is okay, but please, no white in the tutorial.
There should also be "Tips & Hints" with some extra information, or maybe "Suggested Readings". Also, Content of tutorial won't hurt.
 
Level 11
Joined
Sep 28, 2011
Messages
899
I finaly understanded why units with crow form are able to change height it is simply because when they cast the spell they make the morph anim, change height and after become the new unit.
Another way to do what you do without check just create one new ability only for the trick based on crow form.
and when you want to change the heigt of an unit add and remove this ability.
Because no unit have this ability there is no problem.
This tutorial is partially jass so change it category to jass.
Because gui section is for the ones who does not know jass.
 
Last edited:
Another way to do what you do without check just create one new ability only for the trick based on crow form.
and when you want to change the heigt of an unit add and remove this ability.
Because no unit have this ability there is no problem.

True, but in public resources, it would be troublesome.
For a map, that makes sense.
Using the check can still save some space though.
 
Level 30
Joined
Jan 31, 2010
Messages
3,583
One of colors that fit the Hive the most. Nice, and not painful for the eyes. But, now the red stands out too much. Tried with yellow/dark yellow? It would fit the theme and still draw attention, if your aim is to get a cohesive coloration.

Anyways, don't bold the red lines. Use this, this or this instead, with no colors at all, or use pure colors.
 
Level 30
Joined
Jan 31, 2010
Messages
3,583
Sigh... We aim for perfection, but we can't see it's a moving target.

Aesthetically very good, the concept of tutorial is good as well, and the whole tutorial is useful.

Good Job, I have to say.

Oh, the only thing you can do now is to use points. The points will link your table of contents, and when you click, for an example, "Tips", the page will scroll down to that point.
If you need help with points implementation, ask me via Pm / Vm.
 
Top