JASS: Basic

Im_On_56k

Hm...
Reaction score
116
This tutorial includes:
  • 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
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.
Code:
call DisplayTimedTextToForce( GetPlayersAll(), 30, "hello" )
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.

Code:
call DisplayTimedTextToForce
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.
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

attachment.php


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
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.
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
This will declare i as an integer that equals 1.

Here is another example of setting a string when declaring it.
Code:
local string s = "hello"
Now lets use what we have learned in our trigger.

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
Lets make a local string variable that equals hello.
Code:
local string s = "hello"
Make sure that is the very first line after your function.
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
Now lets set our DisplayTimedTextToForce to our local variable.
Code:
 call DisplayTimedTextToForce( GetPlayersAll(), 30, s )
Your trigger should now look like this.
Code:
function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
local string s = "hello"
 call DisplayTimedTextToForce( GetPlayersAll(), 30, s )
endfunction
Now lets use what we learned again and make a local variable that is an integer.

Code:
local integer i = 30
Now lets implant this into our trigger.
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
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.
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)
This will set i to 1.

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
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
JASS:
function GetPercent takes integer i, integer i2 returns integer
//This is a comment and will not have any effect on anything in the function.
return i/i2*100
endfunction



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" )
This will display hello to all players for the value of MyInteger.


By Im_On_56k
 

phyrex1an

Staff Member and irregular helper
Reaction score
447
Overall it is good, hopefully it will give a little push in the right direction for new jassers.

Just want to point out one thing:
Im_On_56k said:
Code:
Function GetPercent takes integer i, integer i2 returns integer
Return i/i2*100
Endfunction
Nothing wrong with the function as it is but the divesion will be calculated as a integer divesion, ie 1/3 = 0 and other error vaules.
If you want a integer return i suggest
R2I(i/I2R(i2))*100
if you change it to a real return
(i*100.)/i2

Also remember that jass is case sensetive, it is function, endfunction and return.
Thats the quind of errors you get when writing in Notepad ^^
 

PB_and_J

level 85 anti-spammer
Reaction score
41
one thing:

I still don't know what this is for //========== ==

and why some lines start a few saces after others

:banghead: (realy I don't know anything about anything about programing :(

However, the tut is nice, now I learned alot from it:).
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
// This is a comment. Whatever comes here is just "decoration" and will be ignored
// Some people strongly feel that comments are a must on any progam
// Others equally strongly feel that the source explains itself

As for the spaces, that's indentation, and greatly improves readability.
As an example, every now and then, someone posts some trigger code without "code" tags around.
Unfortunately, there's nested IFs... after some reading, you don't know anymore what action is in what then or else, or even what if.
Use it, do it, always.
 

SD_Ryoko

Ultra Cool Member
Reaction score
85
Like dis. Heh heh.

PHP:
function Display_Maps()
{
	global
	$script, $username, $userid, $administrators, $ptitle, $HTTP_REFERER,
	$mode, $genre, $page,  $view, $sort,
	$maptypes, $mapmodes, $mapsort;

	if(isset($view)) $sqlquery="SELECT * FROM maps WHERE mapid='$view'";
	else {
		$sqlsort="mapid DESC";
		if(isset($sort))
			{
			if($sort=="1") $sqlsort="mapid ASC";
			if($sort=="2") $sqlsort="downloads DESC";
			if($sort=="3") $sqlsort="author ASC";
		}
		if(!isset($mode)) $mode=0;
		if(!isset($page))  $page=1;
		$perpage=15;
 

XXXconanXXX

Cocktails anyone?
Reaction score
284
This looks alot like and works the same way as Vexorian's tutorial, but doesn't teach half as much, and doesn't grasp the whole concept of JASS.

Why did you make this?
 

PB_and_J

level 85 anti-spammer
Reaction score
41
AceHart said:
As for the spaces, that's indentation, and greatly improves readability.
1 final question: does it make a difference how many spaces, or indentations you have (1,2,3,4 etc), or does it have to be a certain number?
 

Sargon

New Member
Reaction score
83
PB_and_J said:
1 final question: does it make a difference how many spaces, or indentations you have (1,2,3,4 etc), or does it have to be a certain number?

It makes no difference.
 

Im_On_56k

Hm...
Reaction score
116
This looks alot like and works the same way as Vexorian's tutorial, but doesn't teach half as much, and doesn't grasp the whole concept of JASS.

Why did you make this?
Because I felt like it?
Take a look through this thread, there is more than 1 tutorial for some subjects.

I made this in 20 mins and I will be adding onto it.
 

XXXconanXXX

Cocktails anyone?
Reaction score
284
Yes, but you could've made it more original.

You explain it almost exactly as Vexorian did, but left out major portions and didn't grasp the whole concept, just took tidbits from Vexorian's explanation and through it together.
 

Darg

Administrator
Reaction score
49
conan stop throwing accusations around, he wants feedback not snide remarks.

read what he said in the first post:

This is the end of the tutorial, I made this in about 20 mins and I plan to hopefully add more to it later on.

my feedback:

its travelling along well so far, but there are some concerns on my part about the structure. It is vitally important that, when writing any tutorial, that you must show the reader what the end result of the tutorial is at the beginning of the tutorial. For example, if I were to create a similar tutorial to yours, I might say "This tutorial teaches you how to display a text message in the game using JASS". For this I would give an in-game screenshot of some text displaying on the screen and I might put a peasant on the map for good humour. Next, I would outline what JASS concepts I am going to teach in this tutorial, which for me would be something like:

- this tutorial will teach you how to write a basic JASS trigger using local variables and calling functions

After that I would start getting into the nitty-gritty detail.

- writing a basic trigger
- adding local variables
- calling functions

Finally, finish off the tutorial by linking to a map which contains the code that you have just been discussing.


Also, I would personally put the memory leaks section in a completely different tutorial. If you are trying to discuss the basics of JASS it is not the best idea to confuse the reader with memory leak discussions. Memory leaks occur regardless of whether you are GUI coding or JASS coding, so perhaps the better option is to make another tutorial discussing the impact of memory leaks and how you would combat them.
 

Darg

Administrator
Reaction score
49
hey I never saw you had an image attached to the first post, sorry about that! Guess I'm blind...

:)
 
W

Warnicro

Guest
I liked the tutorial better than vexorian's tutorial (no offense against vexorian) but this was easier somehow.

in my oppinion you did a good job, cause I actually pulled it off to make my first jass, I added some things and I even ended up making a cinematic with a few game texts (pre set, with variables :p) and made a small story and made it end again as well with a victory condition.
I thank you dearly for the tutorial, cause I really learned some from it, and I hope you continue, so I can learn some more.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top