Tutorial JASS Tutorial, in detail

Lyerae

I keep popping up on this site from time to time.
Reaction score
105
Now, I purposely left out certain things in this tutorial. Why? So I can properly explain how everything works, in more detail, which I think I've done a decent job of doing.
I wrote this to try to explain things to someone without any programming experience. I know it was hard for me to learn JASS, because people kept throwing things at me that I didn't understand.
So, hopefully with this tutorial, that doesn't happen.

So, here it is:
JASS. The Scripting Language of Warcraft III.
JASS. The thing that will make you want to tear your hair out (no, seriously. It will).

I've seen many JASS tutorials. None of them cover the right things at the right time to teach you how to use
JASS.
So you know what? I'm making one.

First things first.
I assume you have at least a basic knowledge of GUI. If not, that's okay. You can still learn JASS without it.
I also assume you have A) JASS NewGen Pack (JNGP or NewGen) B) JASSCraft or a similar JASS syntax editor.
If you don't have NewGen, at least get JASSCraft (which believe it or not, I'm writing this tutorial in).
It'll help you. A lot.

So before we get into the world of JASS, let me explain a little bit about it.

First, what is JASS? Ask yourself that. If you've read other tutorials, you can answer that. If not, you'll be wondering exactly what it is.
JASS is the Scripting Language (like Lua or JavaScript) that ALL Warcraft III triggers use.
When you create a GUI (also known (incorrectly) as "Triggers"), you are creating JASS code. "BUT I DON'T SEE IT!" you may ask yourself.
That's because the Warcraft III Trigger Editor hides all that JASS code from you, protecting you from things you (most likely) don't
understand.

Go ahead and pull open that World Editor of yours, create a trigger, and click on "Convert to custom code" (or something along those lines).
It'll instantly pull up text where the trigger was before. That, my friend, is JASS coding.
Now, you may see things like "set udg_VariableName = Value" or "function myFunct takes nothing returns nothing" (or something along those
lines. Again). That's all the different little JASS things you'll need to learn to be able to use this language. BUT DON'T WORRY! They're
easy enough to understand once you've learned what each part does.

Now, back to explaining JASS.
Warcraft III has a compiler which will compile all that cool looking JASS code you make, while playing the game.
And that's how you do things like creating a unit, or playing a sound, or triggering events.

But most people, when they first learn JASS, don't realize the power that JASS has. Hell, I still don't know all that it can do.
You can create a lot of different systems in JASS. All MUI, MPI, etc etc.

So, now that your probably bored out of your mind with reading pointless nonsense, lets begin.
Here, is a basic function:
function myFunction takes nothing returns nothing
endfunction

The JASS Compiler (now refered to as "JC" through out this tutorial) will read this, and tell the game "Oh look, here's a function! Let's see what it does..."
Now, to actually make to do something, you need to add function calls to it (confusing, eh?)
Here is another example:
JASS:
function myFunction takes nothing returns nothing
    call BJDebugMsg("Hello World")
endfunction

Now, I'm assuming (there I go, assuming things again) your going "WTF! WHAT IS THIS?!?".
Simple. I'm calling a pre-made BJ (Blizzard JASS... Not what you thought it was, eh?) function called "BJDebugMsg".
This function will call a native called "DisplayTimedTextToPlayer".
What's a native? You'll figure that out soon enough.
All you need to know about BJs and Natives is this:
Natives = Good
BJs = Bad
BJDebugMsg is going to be the only BJ function you ever use.
Now, you'll hear about things called "User Functions". Well, you see that function I made above. That's a user function.

If your wondering what that function will do, it'll display the words (without quotes) "Hello World" to all players.

Moving on...

Lets introduce the first JASS concept.
Local Variables.
(Warning. Basic GUI knowledge needed for this part)
A Local Variable (more commonly refered to as a local) is a variable which only exists inside of the function it was declared in, as
opposed to Global Variables, which all functions can be uses in.
You define a local in a function, before any function calls, or variable setting.
Example:
function myFunction takes nothing returns nothing
local string s = "Well hi thar" // "local" declares a local variable, "string" tells it the type, "s" tells it the the the rest (other than the "=") is the value of the variable
call BJDebugMsg(s)
endfunction

That will create a local string variable, call it s, and give it the value inside of the quotes.
You may use "set" to set the variable to something else. This is also used for globals (read more later).
Example:
JASS:
function myFunction takes nothing returns nothing
    local string s = "Well hi thar" 
    call BJDebugMsg(s)
    set s = "Hello World"
    call BJDebugMsg(s)
endfunction


If you read what I just said before, you'll understand what that does.
If not, Private Message me, and I'll tell you.

So by now, you should have a pretty decent understanding of how this all works, in terms of locals and functions.
If not, I suggest you read a few more tutorials. This is a JASS tutorial, but I expect people to understand things at certain areas (not to call anyone stupid).

Now, I'll teach you how to use Global Variables.
Example of a group of global variables:
JASS:
globals
    integer myInteger = 546
    real myReal = 2654.0564
    string array myString // doesn't get set in the globals block. You need to do that in a function
endglobals


As you can see, it's very easy to define global variables.
Now, there are important things to remember about globals:
1) Globals must be defined in the map header.
2) All Globals can be used by all functions

Now, you may see that I used the "array" keyword. This will define an array. What is an array you ask? It's a variable that can hold multiple values
by using an index.
Example of an array:
JASS:
globals
    integer array myInteger
endglobals
function myFunction takes nothing returns nothing
    set myInteger[0] = 1
    set myInteger[1] = 2
    set myInteger[2] = 3
    set myInteger[3] = 4
    set myInteger[4] = 5
endfunction

Understand how arrays work? Good. If not, read on.
When you define an array, you cannot set the value inside of the globals block. You need to use an index ([number]) as shown above to set it.
Now, the example I showed you above will create an array, and make a function to set 5 indexed (array indexs start at 0), and give them the value of 1 through 5.
An important thing to remember is that you cannot define an array above something that isn't already defined.
Example
JASS:
globals
    integer array myInteger
endglobals
function myFunction takes nothing returns nothing
    set myInteger[0] = 1
    set myInteger[1] = 2
    set myInteger[2] = 3
    set myInteger[3] = 4
    set myInteger[46] = 5
endfunction


That'll give you an error. "But why?" you ask "It looks like the thing you showed us above!"
Well, it is in a way. But if you look at it closely, you'll notice the line that'll cause us all the errors.
set myInteger[46] = 5
Yep, that's it.
"But why does this cause an error? Arrays are supposed to be able to go as high as a couple thousand!"
Because the indexs 4 through 45 have not been defined yet.
Get it? Good. If not, private message me, and I'll be glad to explain.

Lets look at a loop, shall we?
JASS:
function myFunction takes nothing returns nothing
    local integer i = 0
    loop
        set i = i + 1
        exitwhen i = 500
        call BJDebugMsg(I2S(i)
    endloop
endfunction


That's going to loop everything within the loop-endloop blocks, until i is equal to 500.
Now, you may notice the "exitwhen" declaration. This is unneeded, but unless you want it to loop forever, use it.

How about ifs? Know what an if is? No? Perfect. Let's learn then, shall we?
JASS:
function myFunction takes nothing returns nothing
    local integer i = 0
    local integer i2 = 1
    if i > i2 then
        call BJDebugMsg(I2S(i) + "is greater than" + I2S(i2))
    endif
    call BJDebugMsg(I2S(i2) + "is greater than" + I2S(i))
endfunction


Some important things to remember:
1) You can use just about everything in an if, in terms of variable. Reals, strings, integers, booleans, etc.
2) Everything after the endif is considered "else"
3) You can nest ifs.

Simple enough, once you mess around with it a bit.

I'm not quite sure that I have left to talk about in this tutorial... I've pretty much covered everything you'd need to get started...
Oh, I know. Takes and returns.

When you make a function, you'll have three parts that are always the same.
"function takes returns"
Now, we already know what "function" means, but what do the other two mean?
They allow take and return arguements to be used.
Example of a take:
JASS:
function myFunction takes string s returns nothing
    call BJDebugMsg(s)
endfunction
function myFunction2 takes nothing returns nothing
    call myFunction("Hello World")
endfunction


Get it? Good. If not, let's read more.
When you defined "takes string s", you told the function that, when called, it will take a string, and call it s.
We then used that string in BJDebugMsg, to display the string that the function will take. In this case, it's "Hello World".

Basically, that's all there is to it.

How about returns? Returns are evil little bastards which will make no sense to you at all at first. Hell, I still don't understand them properly.
Anyway, let's give you an example:
JASS:
function myFunction takes integer i, integer i2 returns boolean
    if i > i2 then
        return true
    endif
    return false
endfunction


That's really the best way I can describe them. You can return any kind of variable, but you can only return one thing.

So that's about it in my (currently) 213 line tutorial. I hope it's helped you learn JASS, and that you make some pretty kick-ass spells and systems.
Even if you fully understand JASS after this, read another tutorail or two. I know I left a few things out here, for the ease of teaching you the basics, so you should go learn all that.

Anyway, have fun JASSing. I know I do, whenever I get around to it.
Hey, who knows. You could become a "JASS Master" someday.

Thanks for reading my very noobish tutorial,
TheLifelessOne, AKA Lyerae.

(and yes, this was a pain to write. Spent (rougly) 2+ hours on it.)
 

Azlier

Old World Ghost
Reaction score
461
JASS:
globals
    integer myInteger = 546
    real myReal = 2654.0564
    string array myString // doesn't get set in the globals block. You need to do that in a function
endglobals

You should note that freeform globals are a vJass feature.
 

Lyerae

I keep popping up on this site from time to time.
Reaction score
105
I specifically wanted to keep vJASS outside if this tutorial, so I could better explain the normal JASS features, without introducing more... Advanced concepts.
Yeah, vJASS is easy to learn, but not for someone who doesn't even know JASS.
 

Azlier

Old World Ghost
Reaction score
461
Well, you should take the globals blocks out of your tutorial, then. Freeform globals blocks are a vJass feature.
 

Lyerae

I keep popping up on this site from time to time.
Reaction score
105
...?
Globals are just as important as locals.
They can go read a vJASS tutorial if they want to learn all that. This is just to help describe all the JASS (not vJASS) features in detail, really.
 
Reaction score
91
> 1) Globals must be defined in the map header.
Wait, what? Why? You can create globals in libraries and scopes and still access them from everywhere.
You can also note that for globals in a global block there is no need for the "udg_" prefix.
 

Lyerae

I keep popping up on this site from time to time.
Reaction score
105
For like the millionth time, THIS IS A JASS TUTORIAL. NOT vJASS.
>.<
 

uberfoop

~=Admiral Stukov=~
Reaction score
177
For like the millionth time, THIS IS A JASS TUTORIAL. NOT vJASS.
>.<
Then take your freeform globals out of the tut.
Because they are vjass.

JASS:

globals

endglobals



For like the millionth time,
Non-v jass CANNOT do global blocks.



You don't seem to be comprehending that those global blocks you use in jasshelper are NOT the native method. That would be the Variable Editor in the Trigger Editor.
PS the vJass blocks don't NEED to go in the map header. Just generally above the stuff using them.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top