| 11-23-2003, 02:26 AM | #1 |
This is for anyone whose ever programmed before. Common.j and blizzard.j are the equivalant of the API of Jass you can extract them from your war3.mpq Jass is a very odd langauge. Its partially object oriented, in that there are objects, but you can not create your OWN OBJECT TYPES. This is a HUGE reason many people simply find jass not that useful. (Except for on the supreme optimization front). They're wrong of course. Jass is much freer, and allows you to approach the problem from multiple angles. It allows cleaner and less clunky then the capal tunnel syndrome clicking yourself in to a comma triggering. They're many Jass only functions, but lets put them aside. 1 Lets first start off with the Units of Programming, Logic and Flow Operators. Jass doesn't force you to use the hungarian standard of naming convention. This is not a good thing for readability. But I'll be using it in my demo. Code:
function myFunction takes [i]datatype inname[/i], (use the comma operator for each thing the function is passed) returns [i]datatype[/i] return [i](value)[/i] endfunction return will return a value and/or exits this function. This is useful for functions which may have results you don't want to reach... The datatypes are all listed in the common.j file. Jass function CAN NOT BE PASSED OR OUTPUT AN ARRAY. Your inname variable acts like a local variable would. And that brings up our next buddy the local variable. Code:
local datatype localvar [i]set localvar=new value[/i] Jass's assignment operator is the set varname= operator. Jass does not have the accumulators or operator assignment functions (++,--,+= etcetra). You'll note that jass does not use semi-colons. Jass's delimiter is white space. Lets move on: Code:
loop exitwhen boolean [i]true[/i] endloop Finally the last in the series of control: Code:
if [i]boolean[/i] then elseif boolean then else endif elseif acts just like if, but is only reached if the conditions of the if return false. and else will run if no other conditions are met. Finally to actually call your function is done like so Code:
call myFunction(myvar) set myvar=myFunction(myvar2) call myFunction2(myFunction(myvar)) A note on arrays: Arrays in jass are defined with a cap on amount of elements, This does not limit where you assign your elements in the array. You can assign your first value at 0 or 9999999 if you so chose... Arrays in Jass are 1d, but you can make them N-dimensional the same way that C does them. In my case I ussually define a function called Index which will take the amount of values i want and use this formula Where ELimit is the maxium value this dimension of the array will reach. Code:
2d array: X*Ylimit+Y 3d array: X*Ylimit*Zlimit+Y*Zlimit+Z Nd array: 1rstE*2ndElimit*3rdElimit...*NthELimit+2ndE*3rdELimit...*NthELimit+...+N-1thElimit*NthElimit+NthElimit |
