This tutorial includes:
So lets start from the beginning.
Basic look at JASS
Make a new trigger with the event Map Initalization.
Convert it to custom text(JASS) by going to Edit-Convert To Custom Text.
It should now look like this.
It may vary depending on what you named your trigger.
My trigger name was Untitled Trigger 001
We are now going to add an action to it that will display text to all players in
the game.
An action is a function that calls a group of code to do something in the game.
So when we call our function we must put call before the function name as seen above.
The function DisplayTimedTextToForce takes 3 things, so we must give it 3 things.
GetPlayersAll() (playergroup)
30 (integer)
"hello" (string)
GetPlayersAll() is who it will be displayed to in this case it will display to all players.
30 is how long it will display the text in this case it will display it for 30 seconds.
"hello" is the string you will display in this case it will display hello.
All strings must have " around them to declare them as a string.
Now our trigger should look like.
Local Variables
Now we are going to get into local variables.
Local variables are variables that are only used in the function they are declared in.
To declare a local variable it must be at the very top of the function.
To declare a local string we would put.
Local is what tells the game that you are declaring a local variable.
string is the type of variable you are declaring.
mystring is the name of the string you are declaring.
There are many different types of variables but I will list only the most common ones.
Those are the most commonly used variables.
You can also set a local variable when declaring it.
Example
This will declare i as an integer that equals 1.
Here is another example of setting a string when declaring it.
Now lets use what we have learned in our trigger.
To refresh our memory this is what the trigger looked like.
Lets make a local string variable that equals hello.
Make sure that is the very first line after your function.
It should now look like this.
Now lets set our DisplayTimedTextToForce to our local variable.
Your trigger should now look like this.
Now lets use what we learned again and make a local variable that is an integer.
Now lets implant this into our trigger.
Now I will explain to you what our trigger does.
At Map Initalization it will display the text hello to all players for 30 seconds.
Functions
Now lets get into making functions.
A function is a group of code that processes something.
We will put our function into the map script.(the very first thing in the trigger
editor)
We will call our function GetPercent
Our function will take 2 integers and get the percent of them.
So it will divide them by each other and multiply by 100.
Heres how it will start.
Function is telling the game that GetPercent is a function.
GetPercent is the name of the function.
Takes is what the function is taking from you.
Here is an example.
The function DisplayTimedTextToForce takes a playergroup, an integer and a string.
Which is this part.
Returns is what it is giving to you, the oposite of take.
This is used when setting a variable.
Example
This will set i to 1.
Now back to finishing our function. Note the above will not work yet.
Return is what the code is returning as explained above.
Now we must finish our function.
endfunction tells the game that the code for this function ends here.
Comments
// defines a comment in JASS, aswel as many other languages but lets just stick to jass.
Example
Using Global Variables
You have probally used Global Variables if you are experienced enough in the World Editor.
They are like local variables in jass but can be accessed in any trigger.
To use global variables in jass you must place udg_ before the global variable name.
Say we have a global variable named MyVar
To use it in jass we would make it this: udg_MyVar
Here is an example of using a integer global variable in jass.
This will display hello to all players for the value of MyInteger.
By Im_On_56k
- Calling Functions
- Local Variables
- Making Basic Functions
- Making and Using Comments
- Using Global Variables
So lets start from the beginning.
Basic look at JASS
Make a new trigger with the event Map Initalization.
Convert it to custom text(JASS) by going to Edit-Convert To Custom Text.
It should now look like this.
Code:
function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
endfunction
//===========================================================================
function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
set gg_trg_Untitled_Trigger_001 = CreateTrigger( )
call TriggerAddAction( gg_trg_Untitled_Trigger_001, function Trig_Untitled_Trigger_001_Actions )
endfunction
My trigger name was Untitled Trigger 001
We are now going to add an action to it that will display text to all players in
the game.
Code:
call DisplayTimedTextToForce( GetPlayersAll(), 30, "hello" )
So when we call our function we must put call before the function name as seen above.
Code:
call DisplayTimedTextToForce
GetPlayersAll() (playergroup)
30 (integer)
"hello" (string)
GetPlayersAll() is who it will be displayed to in this case it will display to all players.
30 is how long it will display the text in this case it will display it for 30 seconds.
"hello" is the string you will display in this case it will display hello.
All strings must have " around them to declare them as a string.
Now our trigger should look like.
Code:
function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
call DisplayTimedTextToForce( GetPlayersAll(), 30, "hello" )
endfunction
//===========================================================================
function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
set gg_trg_Untitled_Trigger_001 = CreateTrigger( )
call TriggerAddAction( gg_trg_Untitled_Trigger_001, function
Trig_Untitled_Trigger_001_Actions )
endfunction
Local Variables
Now we are going to get into local variables.
Local variables are variables that are only used in the function they are declared in.
To declare a local variable it must be at the very top of the function.
To declare a local string we would put.
Code:
local string mystring
string is the type of variable you are declaring.
mystring is the name of the string you are declaring.
There are many different types of variables but I will list only the most common ones.
Code:
local string s
local integer i
local real r
local boolean b
local location l
local group g
Those are the most commonly used variables.
You can also set a local variable when declaring it.
Example
Code:
local integer i = 1
Here is another example of setting a string when declaring it.
Code:
local string s = "hello"
To refresh our memory this is what the trigger looked like.
Code:
function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
call DisplayTimedTextToForce( GetPlayersAll(), 30, "hello" )
endfunction
//===========================================================================
function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
set gg_trg_Untitled_Trigger_001 = CreateTrigger( )
call TriggerAddAction( gg_trg_Untitled_Trigger_001, function
Trig_Untitled_Trigger_001_Actions )
endfunction
Code:
local string s = "hello"
It should now look like this.
Code:
function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
local string s = "hello"
call DisplayTimedTextToForce( GetPlayersAll(), 30, "hello" )
endfunction
//===========================================================================
function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
set gg_trg_Untitled_Trigger_001 = CreateTrigger( )
call TriggerAddAction( gg_trg_Untitled_Trigger_001, function
Trig_Untitled_Trigger_001_Actions )
endfunction
Code:
call DisplayTimedTextToForce( GetPlayersAll(), 30, s )
Code:
function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
local string s = "hello"
call DisplayTimedTextToForce( GetPlayersAll(), 30, s )
endfunction
Code:
local integer i = 30
Code:
function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
local string s = "hello"
local integer i = 30
call DisplayTimedTextToForce( GetPlayersAll(), i, s )
endfunction
//===========================================================================
function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
set gg_trg_Untitled_Trigger_001 = CreateTrigger( )
call TriggerAddAction( gg_trg_Untitled_Trigger_001, function
Trig_Untitled_Trigger_001_Actions )
endfunction
Now I will explain to you what our trigger does.
At Map Initalization it will display the text hello to all players for 30 seconds.
Functions
Now lets get into making functions.
A function is a group of code that processes something.
We will put our function into the map script.(the very first thing in the trigger
editor)
We will call our function GetPercent
Our function will take 2 integers and get the percent of them.
So it will divide them by each other and multiply by 100.
Heres how it will start.
Code:
function GetPercent takes integer i, integer i2 returns integer
GetPercent is the name of the function.
Takes is what the function is taking from you.
Here is an example.
JASS:
call DisplayTimedTextToForce( GetPlayersAll(), i, s )
The function DisplayTimedTextToForce takes a playergroup, an integer and a string.
Which is this part.
Code:
( GetPlayersAll(), i, s )
Returns is what it is giving to you, the oposite of take.
This is used when setting a variable.
Example
Code:
local integer i = GetPercent(1,100)
Now back to finishing our function. Note the above will not work yet.
Code:
function GetPercent takes integer i, integer i2 returns integer
return i/i2*100
Return is what the code is returning as explained above.
* means multiply.
/ means divide.
+ means addition.
- means subtraction.
Now we must finish our function.
Code:
function GetPercent takes integer i, integer i2 returns integer
return i/i2*100
endfunction
Comments
// defines a comment in JASS, aswel as many other languages but lets just stick to jass.
Example
JASS:
Using Global Variables
You have probally used Global Variables if you are experienced enough in the World Editor.
They are like local variables in jass but can be accessed in any trigger.
To use global variables in jass you must place udg_ before the global variable name.
Say we have a global variable named MyVar
To use it in jass we would make it this: udg_MyVar
Here is an example of using a integer global variable in jass.
Code:
call DisplayTimedTextToForce( GetPlayersAll(), udg_MyInteger, "hello" )
By Im_On_56k