JASS: So You Want to Learn JASS?

emjlr3

Change can be a good thing
Reaction score
395
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:

Code:
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:

Code:
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:

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

Code:
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:

Code:
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:

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

Andrewgosu

The Silent Pandaren Helper
Reaction score
715
I think my little empty head even stored and understood some information what you gave. Excellent!
 
R

R3velati0n

Guest
That helped me alot :p
Nice tut ;)

While your posting on this
In JassCraft i cant find anything for map initilization? What is it called in the editor? thanks
 

Sim

Forum Administrator
Staff member
Reaction score
534
Nice one!

This will surely help countless of people :)

Good job again emjlr3.
 

ReVolver

Mega Super Ultra Cool Member
Reaction score
608
Daxtreme said:
Nice one!

This will surely help countless of people :)

Good job again emjlr3.

Same :shades:

[Moved] Temporary
 

emjlr3

Change can be a good thing
Reaction score
395
R3velati0n said:
That helped me alot :p
Nice tut ;)

While your posting on this
In JassCraft i cant find anything for map initilization? What is it called in the editor? thanks

I should add this in, and I will, later, but yea, there are some things that I don;t remember well, and can't really think of what it would be, liek atm I am at a lost for what event that would be, you can either use JASS Craft, and search for, say, init, or just creat a GUI trigger in the editor, give it that event, and convert it, then you got it, and can put it in your JASS trigger, I do this often, especially for things liek events, that I do not remember

another thing I often do is, when writing spell abilities, give it the event, and the condition that its the correct ability, then convert it

an easy efficiency change, and I got my whole base trigger made for me, in about 10 seconds, where it would take me a few minutes to figure out my events, and type it all if I started from scratch, maybe not the best habit to have, but for me, it is faster and works
 

cr4xzZz

Also known as azwraith_ftL.
Reaction score
51
...

hmmm actually i didn't understood anything... what's the point of makin scripts when u have triggers!?! it's twice as hard! :banghead: !
 

SFilip

Gone but not forgotten
Reaction score
633
1. More possibilities
2. Typing > Clicking
3. Being constantly developed in some ways (Caster System, preprocessors, Handle Vars etc.)
 

emjlr3

Change can be a good thing
Reaction score
395
cr4xzZz said:
hmmm actually i didn't understood anything... what's the point of makin scripts when u have triggers!?! it's twice as hard! :banghead: !

maybe because u did not even read it...

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)
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
Wow... You bumped a rreeeaaalllyyy old thread.

Anyways, if you don't understand GUI or have even a basic knowledge of it, you most likely won't understand JASS.
 
V

Vick Hardy

Guest
Uh,ah, I'm a little confuse,but I will read this as many times I need to learn it! :confused:
 

NetherHawk

New Member
Reaction score
26
anyone know where i can find a tutorial on how 2 use handle vars @_@ how come there are so many tuts on how to learn jass but none on how to advance from there by using systems like handlesvars and caster systems >.>
 

Bronxernijn

You can change this now in User CP.
Reaction score
43
I just did this tutorial. It basically just gave me the extra push to JASS, like using JASSCRAFT, and how locals work. I am familiar with programming, which is a big pre (in my opinion) when doing JASS.

Nice tutorial, well explained. Contains a few minor spelling mistakes.

Good job :)
 

Drazalon

New Member
Reaction score
3
wow. i remember this thread when i first joined...

this is amazing, after a couple years of GUI, i ran through some JASS tutorials, rather than hiding in a corner and avoiding them i learned a loadfull of new things i could of done years ago...

ill look into more jass tutorials and see hwat i can fix myself this time.

+rep even though u deserved it long long long ago
 

Cheesy

some fucker
Reaction score
95
Great tutorial, I too started down the bad road of GUI long ago, and I pity myself for it. :(
 

CaptDeath

New Member
Reaction score
103
wow this makes me want to give up gui like for ever and go to jass
not only that it makes me believe i can do jass
but i cant fucking find jass craft :'(
 

Viikuna

No Marlo no game.
Reaction score
265
You dont need Jass Craft if you have NewGen. NewGen has function list and syntax highlighter and everything.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      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