• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

JASS in detail

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:
JASS:
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:
JASS:
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.)
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
1) Remove those random linebreaks. For example:
I've seen many JASS tutorials. None of them cover the right things at the right time to teach you how to use
JASS.

2) This tutorial has a LOT of random babbling.

3) Why JASScraft? You're getting WE newgen, so you use TESH...
If you don't use TESH then why use newgen? Might as well go for jasscraft + jasshelper.
Oh, and include links to the tools you use.

Ok, so from now on I'm going to pretend I'm a newby who knows nothing of jass.

Here, is a basic function: [...] Here is another example: [...]
Ok, you've just lost me. I'd probably give up learning jass from this tutorial at this point.
You're saying many of the jass tutorials you've read don't cover the right things at the right time.
Well, IMO your first example is not the right time to start babbling about natives, BJ's, functions calling natives, user functions, etcetera. You're scaring people away.
A suggestion: don't bother talking about BJ's just yet. At this point, a newby can't be bothered with knowing what a BJ is, or what separates it from a native. They don't even know what a function is alltogether.

(Warning. Basic GUI knowledge needed for this part)
But at the start of the tutorial you said I *could* do without GUI knowledge?

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.
How can I understand what a local variable is when you haven't explained the concept "function" yet?
IMO the first jass concept you should introduce is functions. No, don't start talking about parameters and returnvalues yet, but a user should definitely understand what a function is before you can explain what a local variable is.
Besides, why not just start with globals first? People probably know globals already from GUI, and you can explain how to declare them without having to explain what a function is. Explaining what a local variable is is cake when you already explained what a global is.

JASS:
    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
Wow, what's that green stuff in there?

That will create a local string variable, call it s, and give it the value inside of the quotes.
Ok, so the value must always be inside of quotation marks? Good to know.

So by now, you should have a pretty decent understanding of how this all works, in terms of locals and functions.
I personally think I'd be pretty confused. I don't even know yet how I actually write my own local variable. I mean, you've given me an example for a string, but what exactly is the general syntax for "any" variable? It also raises some questions such as: what names can I legally give to a variable? Do I always have to initialize them?

1) Globals must be defined in the map header.
No.

Because the indexs 4 through 45 have not been defined yet.
So what? This does not give you an error.

exitwhen i = 500 // Syntax error: this should be "i == 500"
call BJDebugMsg(I2S(i) // Syntax error: you forgot a bracket )

That's going to loop everything within the loop-endloop blocks, until i is equal to 500.
Reword this please. Something more like:
The statements within "loop" and "endloop" are repeated forever. The only way to stop looping is through an "exitwhen" statement, that exits the loop when the condition is met.

1) You can use just about everything in an if, in terms of variable. Reals, strings, integers, booleans, etc.
Actually, everything inbetween if/then must be a boolean expression, i.e. an expression that can be evaluated and found to be either true or false.
For example: i == 100 is a boolean expression because i == 100 is either a true claim or a false claim. As long as it is an expression, you can use it.
Something like "if 100 then" cannot be used because it is an integer, not a boolean.

2) Everything after the endif is considered "else"
No. Everything after the endif happens regardless of the "if" statement. The "else" only happens if the if condition was NOT met, while everything after endif happens anyway.

3) You can nest ifs.

Why do you say you can nest ifs, but you don't say you can nest loops? Be consequent.

Basically, that's all there is to it.
Being the newby as I am, I still have no clue what the takes and returns is about...

I think you should delve into jass some more before you get to write a tutorial.
 
Level 12
Joined
Feb 23, 2007
Messages
1,030
Actually I'd say they all suck. Nobody has ever written a good JASS tutorial for one reason. Once you learn JASS, you can't relate to those who don't know it. Nobody ever uses example a GUI user can understand.

I remember starting off learning JASS (when I was 14). I tried for about a week, to find a tutorial that could help me. Well finally I just learned it on my own by piecing bits of information together. I'd see a script and go *OH I GET IT*. That happened about 100 times and here I am now.
 
Top