| 09-10-2007, 09:45 PM | #1 |
I know most of the syntax (partially from a basic knowledge of C++) and I know how JASS relates to GUI, but what I want to know is that I've seen lots of spells where each line almost is a function, e.g. JASS:function blarg takes ... returns ... (line goes here, usually has to do with a constant) endfunction Just repeated a lot. Why is this there and what exactly is it for? Is there some part of JASS that makes it easier to do that? I want to understand because it will help me make spells entirely in JASS, not just leakless GUI code that has its globals removed and locals added to make MUI. Please somebody explain. |
| 09-10-2007, 10:20 PM | #2 |
well JASS:function Kill2 takes unit a, unit breturns nothing call KillUnit(a) call KillUnit(b) endfunction Well if i were to put that into the custom script part of my map i could do this: JASS:function gg_trg_KillUnit takes nothing returns nothing call Kill2(udg_Thrall, udg_Jaina) endfunction |
| 09-10-2007, 10:23 PM | #3 |
Something like this?? JASS:constant function Spell_SpellID takes nohting returns integer return 'A000' endfunction This is used to set constant values, like the spell rawcodes, AOE values, etc. I suggest to check some tutorials about introduction to JASS, it will give you better lights about this topic. This is a good one: http://www.wc3campaigns.net/showthread.php?t=74894 |
| 09-10-2007, 10:24 PM | #4 |
It lets later users easily change the values of your spell. It's mostly used for spells that are submitted to the public. |
| 09-11-2007, 06:05 AM | #5 |
constant functions like that can be inlined by Vex's optimiser, so at run time they are as fast as not having functions, but have the ease of editing in the WE. |
| 09-11-2007, 06:19 AM | #6 |
Basically it is just so that the spell can conform to the JESP spell standard so it makes it easier for ppl to import and use the spell. |
| 09-11-2007, 09:23 PM | #7 | |
Quote:
I think I get it, but I know I really don't. ![]() |
| 09-11-2007, 09:41 PM | #8 |
ok ill sum it up for ya constant functions are used for the following reasons 1) they are ever so slightly faster normally 2) with vex's optimizer they can become much faster then a non constant 3) because it helps for the distribution of spells to others (look for the constant blocks and change that stuff to modify) HOWEVER constants have some downsides: 1) unmodifiable return values, for example you cant return any value that MIGHT change (even if it doesn't) like strength of a unit level ect 2) are just generally harder to work with due to reason 1 3) constants are mostly useless are parts of a spell such as the creation of special effects, damage ect due to there nature of being a "constant" So basically if you are returning anything but the same number value or w/e don't use them, and honestly it is sometimes better to avoid them altogether if you wont be making a spell public. |
| 09-12-2007, 12:37 AM | #9 | |
This is all false: Quote:
JASS://This constant function Int takes nothing returns integer return 5 endfunction function SomeFunc takes nothing returns integer return Int()+15 endfunction //Becomes this: constant function Int takes nothing returns integer return 5 endfunction function SomeFunc takes nothing returns integer return 5+15 //It might go directly to 20, I'm not sure. endfunction The only thing you can't do with a constant function is call another non-constant function. The following functions are valid: JASS:constant function StrengthBonus takes integer HeroStrength, integer Level returns integer return 25*HeroStrength+5*Level endfunction constant function Duration takes integer HeroStrength, integer Level, real RandomDur returns real return StrengthBonus(HeroStrength, Level)/5.00+RandomDur endfunction JASS:function StrengthBonus takes unit U, integer Level returns integer return 25*GetHeroStr(U)+5*Level endfunction constant function Duration takes integer HeroStrength, integer Level returns real local real RandomDur = GetRandomReal(0.00, -5.00) return StrengthBonus(HeroStrength, Level)/5.00+RandomDur endfunction |
| 09-12-2007, 01:39 AM | #10 |
actually they are faster because once they are called the value is not rederived. So they are the same speed the first time however subsequent times their are a microsecond faster... not that .00001 seconds of extra speed really matters ne ways :/ And vex's optimizer does make the first time faster because calling pure basic values as a return is faster then anything else |
| 09-12-2007, 05:36 AM | #11 |
The function doesn't become faster when optimized. It becomes inlined, which makes it faster, but the function no longer exists. |
