JASS: So You Want to Learn JASS?

Tutorial By emjlr3

So You Want to Learn JASS?

A beginner’s helpful guide to the start of thinking about possibly wanting to learn JASS by emjlr3.

Requirements: Basic/ Advanced knowledge of the WE trigger editor, and some common sense.
A little Program called JASS Craft

Common Myths about JASS:
• GUI is better because it is easier
• JASS is better because it is more difficult
• GUI is easier than JASS: Probably if you want to make small stuff, but if you want to make big things (for example the main feature of your map) JASS is much easier cause it simplifies your code
• You can do everything in GUI: This might be true, but because you can make your own functions in JASS, it is generally much EASIER to make complex things in JASS than in GUI.
• You need to know GUI before learning JASS: It is actually easier to learn JASS without knowing GUI, generally to learn JASS you have to unlearn plenty of things you learned in GUI cause they pollute your mind. That's the reason people that got a lot of experience in GUI might find JASS to not be usable enough.
• You need to know programming to learn JASS: GUI is also a programming language. You can actually learn JASS at the same time you learn programming, and you can learn JASS alone, programming language will appear magically while you learn JASS.
• You need to know XXXX programming language to learn JASS: This is not true at all.
• A map is good because it wasn't made in JASS
• A map is good because it was made in JASS
• A map is good because it wasn't made in GUI
• A map is good because it was made in GUI


JASS Advantages:
If you use JASS directly instead of GUI you win:
• Functions: you can make your own functions and that will save you time
• Efficiency: Typing is faster than clicking with the mouse
• Ability to write more optimized code: GUI's automatization is not flexible enough to make well optimized code and it most of the times will generate really slow code.
• Local variables and multi instancibility : GUI is simply not good to make things multi player proof.
• Access to 'hidden' native functions : For some reasons GUI does not allow you to use a lot of functions like those related to memory leaks (you won't be able to fix a big quantity of memory leaks in GUI)
{Taken from Vexorians JASS info., http://www.wc3campaigns.net/showthread.php?t=78946&highlight=JASS+GUI }


This problem seems to come up far too often recently, and me being the good big green samaritan that I am, decided to try and help all those in need of such a service, thus spawned the "So You Want to Learn JASS" tutorial.

This will not cover how to write effective JASS code, how to clean leaks, moving locals around, or any of that humbug, this is for those of you who think you want to start down the path of the dark side, and succumb to the evil that is JASS.

Let me start by saying this road is long and arduous, unless however you previously know a coding language, then it will be very easy, but for the rest of us, be prepared to be stumped, pissed, spat on, blinded….etc…

Anywho, many people do not know precisely where to begin in this sort of ordeal. So some begin by inserting some custom script into their GUI triggers, mainly for the use of locals. This, I feel, gives a false sense of some basic JASS knowledge. You are not really doing anything, and all you can really do by this, other then the obvious efficiency helper(which if this is your reason for doing so, why use GUI at all…just makes no sense), is to make non-MUI triggers MUI by using locals instead of globals. Yea this can be good and all, but barely even scratches the surface of why JASS is far superior to GUI triggering and severely limits the effectiveness of what you are doing.

So when you get past that phase, or when you hopefully read this first and never get started, let me begin by saying…good choice, alrighty now let us begin.

I must say the easiest way to learn JASS, I felt, was to create your trigger in GUI, and convert it to JASS, while keeping the original GUI trigger, you can compare the two. The lines are going to be in the same order(aside from your Booleans functions), so you can see what your GUI command translates to when converted. Let me show you an example:

Test One Events Unit - A unit Starts the effect of an ability Conditions (Ability being cast) Equal to Animate Dead Actions Special Effect - Create a special effect at (Position of (Triggering unit)) using Abilities\Spells\Human\ThunderClap\ThunderClapCaster.mdl Unit - Explode (Triggering unit) Unit - Cause (Triggering unit) to damage circular area after 0.00 seconds of radius 500.00 at (Position of (Triggering unit)), dealing 100.00 damage of attack type Spells and damage type Normal

That is the GUI code for a spell, now here it is converted to custom script:

function Trig_Test_One_Conditions takes nothing returns boolean if ( not ( GetSpellAbilityId() == 'AUan' ) ) then return false endif return true endfunction function Trig_Test_One_Actions takes nothing returns nothing call AddSpecialEffectLocBJ( GetUnitLoc(GetTriggerUnit()), "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl" ) call ExplodeUnitBJ( GetTriggerUnit() ) call UnitDamagePointLoc( GetTriggerUnit(), 0, 500, GetUnitLoc(GetTriggerUnit()), 100, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL ) endfunction //=========================================================================== function InitTrig_Test_One takes nothing returns nothing set gg_trg_Test_One = CreateTrigger( ) call TriggerRegisterAnyUnitEventBJ( gg_trg_Test_One, EVENT_PLAYER_UNIT_SPELL_EFFECT ) call TriggerAddCondition( gg_trg_Test_One, Condition( function Trig_Test_One_Conditions ) ) call TriggerAddAction( gg_trg_Test_One, function Trig_Test_One_Actions ) endfunction

Of course this looks like a bunch of gibberish to you, and rightfully so, it did to me at first as well, but the first step to success is to not get overwhelmed. How you ask? Well this is how, open our handy dandy program JASS Craft, and it basically does the work for us. Copy that code into JASS Craft, and viola, now it looks all pretty and is more legible.

Now let me explain just a little bit about how triggers works in JASS, so you can get a better understanding of the basic things you will see in most all JASS triggers. First off there are these things called functions. These hold the key to everything. Functions basically do things for you. The function at the bottom InitTrig_Test_One, this is called during the maps init( as are all of these in every trigger you create in the WE), and it does what is inside of the function. For each trigger in the trigger editor your map creates a global trigger variable for it. So what this is doing is creating a trigger with CreateTrigger() and setting your global trigger equal to it.

Every line there after, as like in all functions, are run in order. Now take a look and actually read all your calls, most people just look, shat themselves, and go run and hide in a corner, but not you, your reading my tut. and will fight this monster like the pussy cat it is. From here the rest is self explanatory. To the trigger you just created, you are adding an event, a condition function, and an action function. So when the event happens, the condition function is ran, if it returns true, then the action function is ran. Simple enough.

Now take a look at the condition function, it takes nothing and returns a Boolean. As you should know, a Boolean is either true or false. If it returns true, the actions are ran, so if GetSpellAbilityId() == 'AUan' then it will return true, else it will return false and nothing will happen. How do you know this, well it is quite simple. The event is a unit casting an ability, GetSpellAbilityId(), as you can look up in JASS Craft returns an integer, the id of the ability cast from the event that happened. You compare it to the ability id you want your actions to happen with, and viola. Something to remember, integers like this always need ‘ ‘ around them, and strings always need “ “ around them.

So if our ability is cast, then our condition function returns true, and our action function is ran, so let’s take a look at it. Again, just take a look at the calls, they are usually self explanatory. We are first creating an effect:

call AddSpecialEffectLocBJ( GetUnitLoc(GetTriggerUnit()), "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl" )

What are all those damn parenthesis and what not you ask? Well they are just this, AddSpecialEffectLocBJ, just like your action function, is another function that you are “calling” to do something for you, a quick search in JASS Craft tells us that.

function AddSpecialEffectLocBJ takes location where, string modelName returns effect set bj_lastCreatedEffect = AddSpecialEffectLoc(modelName, where) return bj_lastCreatedEffect endfunction

It takes a location and a string, and returns an effect. Functions can take things and return things, just like our condition function returns a Boolean. This takes the location where, and the string modelname, and returns the effect that is created. If we take a look back at our GUI trigger, you can see this in it as well:

Special Effect - Create a special effect at (Position of (Triggering unit)) using Abilities\Spells\Human\ThunderClap\ThunderClapCaster.mdl

Create a special effect at a location, using the model thunderclap, wow that looks very similar to our custom script call now doesn’t it?


Take a look at the rest of our actions functions the same way. Look at what it actually says, and that can give you an idea of what it is doing. Then compare it to the GUI trigger, and you can see that things are not so different.

Now our JASS trigger is MUI without locals, but how would we use locals for it?? Well lets see:

function Trig_Test_One_Conditions takes nothing returns boolean if ( not ( GetSpellAbilityId() == 'AUan' ) ) then return false endif return true endfunction function Trig_Test_One_Actions takes nothing returns nothing local unit u = GetTriggerUnit() local location l = GetUnitLoc(u) call AddSpecialEffectLocBJ( l "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl" ) call ExplodeUnitBJ( u ) call UnitDamagePointLoc( u 0, 500, l, 100, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL ) endfunction //=========================================================================== function InitTrig_Test_One takes nothing returns nothing set gg_trg_Test_One = CreateTrigger( ) call TriggerRegisterAnyUnitEventBJ( gg_trg_Test_One, EVENT_PLAYER_UNIT_SPELL_EFFECT ) call TriggerAddCondition( gg_trg_Test_One, Condition( function Trig_Test_One_Conditions ) ) call TriggerAddAction( gg_trg_Test_One, function Trig_Test_One_Actions ) endfunction

Locals must be at least established at the beginning of the function they are used in, and can only be used in the function that they are created, but can be set whenever. As you can see, I create a local unit with “local unit u” and set it equal to the GetTriggerUnit(), or the caster of the ability, I also get his position and set that to a local variable l. I use those in place of what they refer to.

This is the very basics of understanding JASS and beginning to learn it. Actually, I am not so sure I would call it learning it, if you know GUI, you know JASS, you just do not have the custom script memorized that the GUI call refers to. No one does, not me that is for sure, which is where JASS Craft comes in. It knows all of them, so you do not have to. It also tells you what the take and what they return. I never code in the WE and I suggest you do not either.

Now that you can begin learning JASS, I suggest you start by taking simple GUI triggers, like the one I had above, converting them to custom script, and just delving into them, making sure you understand it, and making yourself familiar with not only the structure, but also the functions. Like I said above, you don’t need to know all the functions, but knowing as many as you can helps you code faster, I mean, looking up everything you need to know can become quite lengthy.

Once you have done this, try using locals instead of globals in your triggers, and go from there. I highly suggest you try reading some if not all of the JASS tutorials around the site you can find, more then once even if you are a little unsure of yourself, for they will help you become a lot more familiar with all the in and outs.

Another suggestion I can make is if you are not sure of something in JASS to search for it in JASS Craft, or find it faster do get certain things from GUI, just write it and convert it.

From here on out it is just time on your side that can help. The more your practice, the more you will know, and the better you will get. In anycase, good luck, and happy JASSing.



V 1.00
That is all for now folks, thank you for reading this, and I hope a cleared a thing or two up, and gave you a push in the right direction. This will hopefully be updated at a later date, as time permits and the need warrants.

Click here to comment on this tutorial.
 
 
Blizzard Entertainment, Inc.
Silkroad Online Forums
Team Griffonrawl Trains Muay Thai and MMA fighters in Ohio.
Apex Steel Pipe - Buys and sells Steel Pipe.