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.
  • 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
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      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