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

[JASS] Wyrmlord and his Tut's

Status
Not open for further replies.

Rui

Rui

Level 41
Joined
Jan 7, 2005
Messages
7,550
I've been learning JASS from wyrmlord's tutorials but he seems to be inactive ever since June.

However, the tutorials don't seem to be complete. They don't cover constants and other stuff (unless I read but forgot). Is wyrmlord coming back to complete them or is someone else taking over the work? I would really like to keep learning more, since JASS looks pretty easy when on tutorials (actually harder when one has to do it on his own XD).

I learnt pretty much from the tutorials though, even improved by leak-removal knowledge, I didn't know locals were considered leaks when not removed. GJ.:thumbs_up:
 
JASS:
constant function Spell_Id takes nothing returns nothing
    return 'A000'
endfunction
A constant function is mostly used in spells or systems for configuration:
JASS:
constant function Damage takes real level returns real
    return 50+50*level // 100/150/200/250
endfunction
constant function AoE takes real level returns real
    return 200+75*level // 275/350/425/500
endfunction
They are then used as another normal function:
JASS:
    local unit cast=GetTriggerUnit()
    local integer lvl=GetUnitAbilityLevel(cast, Spell_Id())
    call UnitDamagePoint(cast, 0, AoE(lvl), 0, 0, Damage(lvl), false, false, null, null, null)
The advantage of constant functions is that they are slightly faster than normal functions.
 
  • Like
Reactions: Rui
Well, PJass doesn't syntax this:
JASS:
constant function RawCode takes nothing returns integer
    return 'A000'
endfunction
constant function RawCodeUsage takes unit u returns integer
    return GetUnitAbilityLevel(u,RawCode())
endfunction
So I believe that calling another constant function isn't a limitation.

I don't think constant functions have many limitations. Constant functions are usually used in spells though. It makes the spell more configurable. Say that a spell has a rawcode of 'A000' in the spell map, but your spell for it has a rawcode of 'A002' or something. If you have a constant function like this:
JASS:
constant function rawcode takes nothing returns integer
    return 'A000'
endfunction
function GetUnitAbilId takes nothing returns boolean
    return GetSpellAbilityId() == rawcode()
endfunction
You can easily change the 'A000' to 'A002' as so:
JASS:
return 'A002'
Below, is the function GetUnitAbilId... This is the condition that checks if the ability id is equal to the rawcode.

So it uses "rawcode()" so that means that it will return 'A002'. :D

You may have noticed "rawcode()"... This [()] symbolizes the parameters, or what the function takes.

For rawcode, it has:
JASS:
constant function rawcode !! takes nothing !! returns nothing

Within the "!!", there is the "take" area. Since it takes nothing, you need to put nothing inside the parentheses.

If it took something such as a unit. You would need to do:
rawcode(<UNIT>)

Eg:
JASS:
rawcode(GetTriggerUnit())

The constant function would have "takes unit <NAME>" in it because of it. <NAME> can be whatever you want, it is just a way to symbolize the parameter, like a variable. :)

So, when calling a function, you must always have the parentheses "()" along with it. It is like calling a regular function such as:
KillUnit(GetTriggerUnit())

This, also has parentheses. So does "GetTriggerUnit()".

:smile:

So, hopefully you have a pretty clear understanding of constant functions. The other type of constant is like "constant native". But those are regular natives by Blizzard such as:
JASS:
constant native GetTriggerUnit takes nothing returns unit

This "GetTriggerUnit()" is an example of a constant native. :)
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
You may not call non-constant functions from within constant functions, purge.

Also, apparently constant functions are a tiny bit faster, but it doesn't really make a difference.

More importantly, for spell configuration, Vex's Optimizer inlines 1-line constant functions into the script for easy readability yet good efficiency.

And constant natives are just excuses to allow you to call a few natives within your own constant functions.

Basically, constant functions are supposed to be functions that return a 100% reliable result.
 
Status
Not open for further replies.
Top