Introduction
First part - why JASS?
Why JASS and not GUI? Because JASS is:
- easy to make MUI.
- more efficient.
- you get more control over your code.
- easier to use. (yes, actually.)
And to you who doesn't know: you can't say that GUI is better and another thing than JASS. Why? Because GUI
is JASS.
Second part - Goodies and badies?
Yes, there
is goodies and badies - the goodies are stuff named "natives" and the badies are stuff named "BJs". BJs are functions (explained below) that are created by Blizzard (well, everything in JASS is.), which they used for GUI. The reason BJs is badies is:
- they use natives to work.
- they are slower than natives.
NOTICE - don't worry! I will explain what natives, BJs and functions is below this piece!
But, there is also good BJs! The BJ-variables. Now, in GUI, when you use "Get Last Created Unit", you actually use the function named "GetLastCreatedUnit()" in JASS. Now, all that GetLastCreatedUnit() does, is that it returns a BJ variable - this one:
This is a variable, also created by Blizzard, but because it doesn't call another function, it isn't slow. Therefore: goodie.
NOTICE - there is also good BJs! When debuging, many people uses this function:
this displays a message to all players, and can be used to check which triggers run and which doesn't. There is of course also much more good BJs, try looking around in the function list in TESH!
Third part - JASS basics.
JASS is basicly made up by functions and variables. Now, in functions, there is "subcategories", named natives and BJs.
Functions.
A function would be the following:
JASS:
call UnitApplyTimedLife(myUnit, myBuff, myDuration)
Now, this is a function - this would be adding a life timer in GUI. So, this function requires:
- myUnit - a unit variable. (doesn't have to be a variable though.)
- myBuff - a buff raw code. (in object editor, press ctrl + d to view raw codes)
- myDuration - this is a real. If I placed "2" in this one, the unit (myUnit) would die after 2 seconds. (just an example.)
NOTICE - a function calling another function that you have made, can't be over the function you call!
JASS:
function A takes nothing returns nothing
call B ()
endfunction
function B takes nothing returns nothing
endfunction
// That will cause syntax errors.
Creating your own function.
Now, to create your own function for use, you'll have to do this:
JASS:
function myFunction takes nothing returns nothing
endfunction
This will create a function for use. Now, this function can content other function calls, which will make this function do something.
Then there are something named arguments, like this:
JASS:
function myFunction takes unit u returns nothing
endfunction
There, you could do something with unit u, and when calling the function, you would do this:
Just like when calling the native function above!
If you about to get this, I suggest you to read that all over.
NOTICE - you can have more arguments by adding commas, like this:
JASS:
function myFunc takes unit u, integer i returns nothing
endfunction
Now, we do miss something, don't we? Returns..?
JASS:
function myFunc takes unit u, integer i returns integer
return 0
endfunction
The "returns
integer" part - the integer is the returned variable type. This could have been boolean, unit, group, everything as well though. Now, what is returning? A lot of functions, native and BJ, returns stuff, example:
JASS:
constant native function GetTriggerUnit takes nothing returns unit
This is a function you use for getting the triggering unit, right? Now, for making this function have an effect, it has to return something. Basicly, if a function doesn't take anything and doesn't return anything and doesn't set some variable, it pretty much does nothing. (Isn't always true though.) Now, set can actually set a variable to a return. Example:
JASS:
set myUnit = GetTriggerUnit()
Now, actually, myUnit isn't set to the function GetTriggerUnit(), it is set to the variable the function
returns. Get it? Good!
Calling a function.
Now, every single time you need a function, you'll have to call it - what does that mean? Basicly calling is the same as executing something, like if you wanted to take a step, your mind would "call" a function that made you walk.
When using a function, you'll always need to place call before the function name.
JASS:
call UnitApplyTimedLife(...)
NOTICE - when calling functions, you cannot have
You'll have to use (), where there needs to be the variables you want to call the function with inside the ()s! If the function doesn't take any arguments, you'll just go straigth ()!
Variables.
Locals.
In JASS variables, there are two types of variables - locals and globals. (globals requires vJASS, which is found in NewGen.) Locals are variable types which only are available for use in the function they were declared in.
JASS:
function myFunc takes nothing returns nothing
local integer int = 0
local unit u = GetTriggerUnit()
endfunction
NOTICE - locals will cause syntax errors if another variable or function has the same name as the local!
If I used the variables int and u in other functions, I would have syntax errors.
Globals. (Requires vJASS!)
Globals, as the opposite of locals, can be accessed in every function in the map, and will, like globals, cause syntax errors if a variable or function is declared with the same name as the global.
Globals always needs to be in global "tags", like this:
JASS:
globals
integer i = 1
unit u = null
real r = 2.00
// and so on...
endglobals
These variables will be able to be accessed all over the map.
Arrays.
Now, an arrayed variable is a variable "with more of the same type in it". If you got an arrayed variable, you can set more of the same variable, example:
JASS:
local integer array i
set i[1] = 0
set i[2] = 1
set i[3] = 2
set i[4] = 3
// and so on...
NOTICE - arrayed variables can't be initialized!
Constants.
A constant variable can't be changed throughout the game, and will cause syntax errors if you try.
JASS:
globals
constant integer i = 0 // This will stay 0 throughout the whole game.
unit u = null // This one can be changed, because it's non-constant
constant real r = 2.00 // Again, can't be changed
endglobals
Now, locals can't be constants.
Why is this useful? This can be useful for ability raw codes and condition functions.
NOTICE - functions can be constant too!
previous - home - next