Constant Functions

Ayanami

칼리
Reaction score
288
So I've been pondering about constant functions. I heard that constant functions always return a constant return value. However, this seems to work.

JASS:

private constant function GetDamage takes integer level returns real
    return level * 5.
endfunction


By right, the above function can't be a constant, right?
 

Solmyr

Ultra Cool Member
Reaction score
30
A constant function is a function that does not call any other non-constant functions and does not use the [ljass]set[/ljass] statement. Following this, the function you posted is indeed constant.

In practice, constant functions are used (as your example shows) to denote data such as spell configuration. In terms of execution speed, it is absolutely the same as a non-constant function, however, Vexorian's map optimizer will always try to inline constant functions, which would ultimately result in a minor speed gain (note that JassHelper can also inline stuff, but the optimizer's inlining is much more "powerful"). There's also a consant function inliner by blu_da_noob (I haven't tested that one recently, but last time I did, it worked fine).
 

emjlr3

Change can be a good thing
Reaction score
395
really the idea is, you allow users easy customization of spells/systems using the constant function - but then enable the speed efficiency of in-lining during processing
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top