wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Tutorials > JASS/AI scripts tutorials
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 12-24-2006, 04:51 AM   #1
darkwulfv
Alpha Male of Wc3c
 
darkwulfv's Avatar


Official Map Reviewer
 
Join Date: Mar 2006
Posts: 3,646

Submissions (6)

darkwulfv is just really nice (270)darkwulfv is just really nice (270)

Send a message via AIM to darkwulfv
Default Collected JASS Lessons

This is a series of JASS tutorials for the brand new learner. It breaks down the aspects of JASS into easy to follow lessons. This is an ongoing tutorial, and any and all feedback is greatly appreciated and wanted. We are still working on this, more lessons are on the way!

Rule of Thumb:
Me and Moyack's tutorials will be in Word Document form; Wyrmlord's will be in HTML (a webpage basically).


Credits are given to:
Darkwulfv (Intro)
Wyrmlord (Lesson 1)
Darkwulfv (Lesson 2)
Wyrmlord (Lesson 3)
Moyack (Lesson 4)
Wyrmlord (Lesson 5)
Darkwulfv (Lesson 6)
Wyrmlord (Lesson 7)

We hope these tutorials will help!
Make sure that if you plan on repping, you rep all of us (if you can). We are all working on this together.

Happy JASSing!
~Darkwulfv, Wyrmlord, Moyack, and The)TideHunter(

UPDATE: 5/1/07 ~Latest version is up, redownload!~
Attached Files
File Type: zip JASS Tutorials.zip (26.9 KB, 1175 views)
__________________
The Spell Request Thread
Quote:
Originally Posted by Joe-Black-5
a dota like map but with unique stuff
(There was no map attached, and that was all the thread said.)
Spells I've Made

Darkwulfv's Lightning Grapple || Tritanis' Lazy Bolt


Last edited by darkwulfv : 05-02-2007 at 01:58 AM.
darkwulfv is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 12-24-2006, 04:59 AM   #2
darkwulfv
Alpha Male of Wc3c
 
darkwulfv's Avatar


Official Map Reviewer
 
Join Date: Mar 2006
Posts: 3,646

Submissions (6)

darkwulfv is just really nice (270)darkwulfv is just really nice (270)

Send a message via AIM to darkwulfv
Default

Intro: (By Darkwulfv)
Quote:
Tutorial 1: Welcome to the world of JASS.

What is JASS?
-JASS is the programming language used by the Wc3 engine.

What is GUI?
-GUI stands for Graphic User Interface. It is the default crap used by the trigger editor, made to make triggering easier. Unfortunately, Blizzard made it harder. GUI is bad. It uses BJ's (which will be covered later on), inefficient code, and is overall messy and limiting.

Why use JASS? Can't I just use GUI?
-Sure, you can use GUI. It's not recommended anymore, but it's not dead or nothing.

Here are the Pros of JASS:
-Easier to write out
-Faster, more efficient, and no leaks (when done properly that is)
-Breaks many restraints created by GUI
-Doesn't use BJ's (which again is possible when done correctly)
-Neater, easier on the eyes for longer triggers
-Easier to copy/paste, and can be edited in a text editor or 3rd-party editors (such as JASScraft)
-Generally faster to do when you get the hang of it. Much less clicking around.

However, you must be careful with JASS. As great as it is, it must be used correctly. One single mis-type can screw up an entire trigger.

Will it be hard to use?
-If you've programmed anything before, JASS will be much easier. Even if you haven't, its still pretty easy. It'll take some getting used to, and can be frustrating. You may even feel like reverting back to GUI, but don't. This is worth it. Very complex things will obviously be harder, but we're gonna start you off easy.


How do I get JASS in my editor?
-Make a trigger and name it. Then go to Edit -> Convert to Custom Text. This cannot be reversed. Now edit away!

I'm having trouble typing JASS in the WE!
-Use a 3rd party program for some help. JASScraft and Silly JASS Utility are 2 I would suggest for anyone. Both can be found on the site. JASScraft is perfect for editing your new JASS, since it gives function names, native lists, and Take/Return values, plus a good syntax checker, and more. Defiantly a must-have.

When I try to save or test, I get a ton of errors!!
-You probably have a typo or two somewhere, or an nonexistent function. Check all your code and JASS is VERY case sensitive. If you type an "A" where an "a" should be, you will get an error. Also, check to make sure there aren't other errors. JASScraft can assist you here. That's why we recommend editing your codes in JASScraft. Much much much easier.

So what's the first step to learning JASS?
-Forget everything you know about GUI, except for globals. JASS is far different from GUI, and trying to compare them is a bad idea. However, a good first step is to make some triggers in GUI, then make them JASS. Throw them into JASScraft and have a ball converting BJ's to natives and cleaning leaks. You'll learn fast. It defiantly helps the crossover from GUI to JASS.
__________________
The Spell Request Thread
Quote:
Originally Posted by Joe-Black-5
a dota like map but with unique stuff
(There was no map attached, and that was all the thread said.)
Spells I've Made

Darkwulfv's Lightning Grapple || Tritanis' Lazy Bolt


Last edited by darkwulfv : 12-24-2006 at 05:01 AM.
darkwulfv is offline   Reply With Quote
Old 12-24-2006, 04:12 PM   #3
wyrmlord
User
 
wyrmlord's Avatar
 
Join Date: Feb 2006
Posts: 399

Submissions (2)

wyrmlord has a spectacular aura about (77)wyrmlord has a spectacular aura about (77)wyrmlord has a spectacular aura about (77)

Default Lesson 1: "Hello World"

The same as Lesson 1 in the first post, only formatted with HTML to improve how it looks.

Hmm, I can't upload HTML files so here's a zip file with the HTML file inside of it.
Attached Files
File Type: zip Lesson1.zip (1.9 KB, 196 views)
__________________
A member of Clan TDG - Quality mapmaking and playtesting.

Tired of boring old GUI? Want to learn JASS? Take a look at these tutorials.
wyrmlord is offline   Reply With Quote
Old 12-24-2006, 10:02 PM   #4
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,905

Submissions (37)

Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)

Hero Contest #3 - 2nd Place

Default

Hi, if you use friging gVim (use google) and JASS.vim (my sig) you can highlight vim code and save the highlighted code as html (kind of like WE/JASSHelper readmes)
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 12-24-2006, 10:45 PM   #5
darkwulfv
Alpha Male of Wc3c
 
darkwulfv's Avatar


Official Map Reviewer
 
Join Date: Mar 2006
Posts: 3,646

Submissions (6)

darkwulfv is just really nice (270)darkwulfv is just really nice (270)

Send a message via AIM to darkwulfv
Default

Lesson 2 is here!! It's in the first post.
__________________
The Spell Request Thread
Quote:
Originally Posted by Joe-Black-5
a dota like map but with unique stuff
(There was no map attached, and that was all the thread said.)
Spells I've Made

Darkwulfv's Lightning Grapple || Tritanis' Lazy Bolt


Last edited by darkwulfv : 12-24-2006 at 10:48 PM.
darkwulfv is offline   Reply With Quote
Old 12-25-2006, 12:40 AM   #6
darkwulfv
Alpha Male of Wc3c
 
darkwulfv's Avatar


Official Map Reviewer
 
Join Date: Mar 2006
Posts: 3,646

Submissions (6)

darkwulfv is just really nice (270)darkwulfv is just really nice (270)

Send a message via AIM to darkwulfv
Default

... Nice to know...
Any comments on the tutorial(s)? or didnt you view it/them?
__________________
The Spell Request Thread
Quote:
Originally Posted by Joe-Black-5
a dota like map but with unique stuff
(There was no map attached, and that was all the thread said.)
Spells I've Made

Darkwulfv's Lightning Grapple || Tritanis' Lazy Bolt

darkwulfv is offline   Reply With Quote
Old 12-25-2006, 01:31 AM   #7
wyrmlord
User
 
wyrmlord's Avatar
 
Join Date: Feb 2006
Posts: 399

Submissions (2)

wyrmlord has a spectacular aura about (77)wyrmlord has a spectacular aura about (77)wyrmlord has a spectacular aura about (77)

Default

Quote:
Originally Posted by WILL THE ALMIGHTY
slightly off-topic: Daelin is making a JASS "school" on hive.
Wow, someone had nearly the exact same idea that I did. Only Daelin's thought is a school while mine was a large JASS tutorial like you'd see for programming languages. Anyways, lesson 3 is almost finished, and when I finish with it I'll mess around with Vex's suggestion.

EDIT: A bit confused as to how to use gVIM with Vex's file.

EDIT 2: I think I figured out the gVIM thing, and now here's lesson 3: Functions
Attached Files
File Type: zip Lesson3.zip (2.1 KB, 99 views)
__________________
A member of Clan TDG - Quality mapmaking and playtesting.

Tired of boring old GUI? Want to learn JASS? Take a look at these tutorials.

Last edited by wyrmlord : 12-25-2006 at 02:24 AM.
wyrmlord is offline   Reply With Quote
Old 12-25-2006, 03:59 AM   #8
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,905

Submissions (37)

Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)

Hero Contest #3 - 2nd Place

Default

Quote:
Originally Posted by WILL THE ALMIGHTY
slightly off-topic: Daelin is making a JASS "school" on hive.

Delete this message if necessary.
Thanks for being useless.

...

I meant It would be good to have highlighting in the html, another way would be to use the pastebin to generate the highlighting and then merge stuff, it was easier for me with vim.

..
Edit, I see you got able to highlight it, I think I am gonna wait till you finish everything and then you have the entire tutorial in a single zip. And then aproval, there are also chances it is gonna require corrections, I think griffen had something to say
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 12-25-2006, 08:29 AM   #9
Jacek
Banned
 
Join Date: Dec 2004
Posts: 1,095

Submissions (1)

Jacek is a jewel in the rough (164)Jacek is a jewel in the rough (164)

Send a message via MSN to Jacek
Default

Quote:
-JASS is the programming language used by the Wc3 engine.
I'd name it a scripting language
Quote:
-Easier to write out
Maybe, but good luck when you have to debug long spells
Quote:
-Doesn't use BJ's (which again is possible when done correctly)
Would you like some fries with that?
Quote:
-Neater, easier on the eyes for longer triggers
Right, especially with Vexorian's optimizer
Quote:
-Generally faster to do when you get the hang of it. Much less clicking around.
You forgot to count keyboard keys as "clicking"

Quote:
However, you must be careful with JASS.
Right, it may blow!
Quote:
So what's the first step to learning JASS?
-Forget everything you know about GUI, except for globals. JASS is far different from GUI, and trying to compare them is a bad idea. However, a good first step is to make some triggers in GUI, then make them JASS. Throw them into JASScraft and have a ball converting BJ's to natives and cleaning leaks. You'll learn fast. It defiantly helps the crossover from GUI to JASS.
I never care about leaks and BJs, only in 0.01 triggers but ok
Quote:
Collapse JASS:
function variable_test takes nothing returns nothing
  local unit u = GetTriggerUnit()
    call KillUnit(u)
    call KillUnit(GetTriggerUnit())
endfunction 
They both work, but which one looks neater?
Obviously the second one, because you don't have to mess with nullifying the variable
TIME FOR CHALLENGE!
Quote:
Collapse JASS:
 function variable_challenge takes nothing returns nothing
  local noob n = GetTriggerUnit()
    call KillUnit(n)
set n = dead
endfunction 

Last edited by Jacek : 12-25-2006 at 08:37 AM.
Jacek is offline   Reply With Quote
Old 12-25-2006, 08:39 AM   #10
blu_da_noob
Nonchalant
 
blu_da_noob's Avatar


Respected User
 
Join Date: Mar 2006
Posts: 1,933

Submissions (2)

blu_da_noob is just really nice (398)blu_da_noob is just really nice (398)blu_da_noob is just really nice (398)blu_da_noob is just really nice (398)blu_da_noob is just really nice (398)blu_da_noob is just really nice (398)

[Quicksilver #2] - 2nd Place[Quicksilver#1] 1st place

Send a message via MSN to blu_da_noob
Default

Quote:
Right, especially with Vexorian's optimizer

I'd say that incredibly stupid comment almost invalidates your entire post.

Quote:
You forgot to count keyboard keys as "clicking"

If I had to give one reason to go to JASS from GUI, I would just say GUI arithematic. There's nothing like having to redo a whole 20 window calculation to change one thing. (joking obviously >.>)

Quote:
Right, it may blow!

Only if you're still using normal WE and don't use a separate text editor with PJass.
blu_da_noob is offline   Reply With Quote
Old 12-25-2006, 08:40 AM   #11
Jacek
Banned
 
Join Date: Dec 2004
Posts: 1,095

Submissions (1)

Jacek is a jewel in the rough (164)Jacek is a jewel in the rough (164)

Send a message via MSN to Jacek
Default

MERRY CHRISTMAS
Jacek is offline   Reply With Quote
Old 12-25-2006, 11:24 AM   #12
darkwulfv
Alpha Male of Wc3c
 
darkwulfv's Avatar


Official Map Reviewer
 
Join Date: Mar 2006
Posts: 3,646

Submissions (6)

darkwulfv is just really nice (270)darkwulfv is just really nice (270)

Send a message via AIM to darkwulfv
Default

I agree with Blu, GUI arithmatic was hell. Especially the long stuff. JASS is just plain easier than GUI once you learn.
Anyone have any useful critique or suggestions on how to make this tutorial better?
__________________
The Spell Request Thread
Quote:
Originally Posted by Joe-Black-5
a dota like map but with unique stuff
(There was no map attached, and that was all the thread said.)
Spells I've Made

Darkwulfv's Lightning Grapple || Tritanis' Lazy Bolt


Last edited by darkwulfv : 12-25-2006 at 11:26 AM.
darkwulfv is offline   Reply With Quote
Old 12-25-2006, 02:10 PM   #13
Jacek
Banned
 
Join Date: Dec 2004
Posts: 1,095

Submissions (1)

Jacek is a jewel in the rough (164)Jacek is a jewel in the rough (164)

Send a message via MSN to Jacek
Default

My critique is useful.
Jacek is offline   Reply With Quote
Old 12-25-2006, 06:46 PM   #14
moyack
Evil Emoticon
 
moyack's Avatar


Respected User
Project Leader: PoC
 
Join Date: Jan 2006
Posts: 3,269

Submissions (17)

moyack is a splendid one to behold (661)moyack is a splendid one to behold (661)moyack is a splendid one to behold (661)moyack is a splendid one to behold (661)

AI Tournament #2 - 2nd PlaceHero Contest - Second place

Send a message via MSN to moyack
Default Lesson 4. IF/THEN/ELSE and LOOP structures.

Tutorial No 4. if/then/else and loop structures. By Moyack.

These kind of structures are the most important in any programming language. In JASS, these structures are quite versatile and useful.

Let's see the first structure: IF/THEN/ELSE

To work with it, we can write it in this way.

Collapse if/then/else structucture:
if <condition 1 function or variable> then
    <Condition 1 script>
elseif <condition 2 function or variable> then
    <Condition 2 script>
...
else
    <Else condition script>
endif

Now you understand why I said versatile :)

As you can see, the conditions must be a function which have to return a boolean variable type (true/false) or a boolean variable. Other interesting feature with the if/then/else structure in JASS, is that it can be used as a multiselection structure too, something very useful in many cases.

In order to ensure the understanding of this structure, This is a small example showing the IF/THEN/ELSE in action

Collapse IF/THEN/ELSE example:
function Set_Damage_To_Unit takes integer level returns real
    // this example will set the damage amount in a spell, according to a level
    // (unit level, ability level, etc)
    local real dam
    if level < 2 then
        set dam = 0
    elseif level == 1 then
        set dam = 50. 
        // probably you noticed the point after the number. this is used to indicate the number is a real one.
        // Is a good programming practice to do that in order to avoid annoying debugging mistakes.
    elseif level == 2 then
        set dam = 63.
    elseif level == 3 then
        set dam = 125.
    else
        set dam = 125. + 50. * (level - 1)
    return dam
endfunction

Here, we are using a local variable which will have a value according to the input argument in the function, and then that variable will be returned by the function.

Important note:
If any IF or ELSEIF clauses apply, then the ELSE clause will be avoided. This example function has a bug by purpose, in order to show an IF/THEN/ELSE characteristic. if level = 1, then the first clause will be executed (set dam = 0). Then the second condition will be executed and will be true too (elseif level == 1), then it will execute the second clause (set dam = 50). With that we can see that the IFTHENELSE structure can be used to make data filtering, for instance.



Now let's see the LOOP structure.

Loops in programming are used to make a set of instructions to be executed several times. Loops can be classified by finite and infinite, the finite loops are which have a defined a fixed number of repetitive executions, controlled by an exit control. The Infinite loops in the other hand, will execute the script contained in it indefinitelly.

The loop structure is as following:

Collapse JASS:
loop
    <Here you can put code too :)>
    exitwhen <condition function or variable>
    <your iterative script>
endloop

This structure is quite flexible as you can see, because you can put the exitwhen condition in ANY place inside the loop. Let's see an example.

Collapse Loop example:
function Heal_Unit_Group takes group g returns nothing
    // this example will heal all units in a unit group.
    local unit u // a local unit variable
    loop
        set u = FirstOfGroup(g) //Selects the first unit in the group.
        exitwhen u == null // the loop will finish when the group will be empty,
        // in tother words, when the FirstOfGroup() function returns null
        call SetUnitState(u, UNIT_STATE_LIFE, GetUnitState(u, UNIT_STATE_MAX_LIFE))
        //sets the life of the selected unit at its maximum.
        call GroupRemoveUnit(g, u) // removes the unit from the group
    endloop
    call DestroyGroup(g) // to avoid group leaks, we must destroy the group variable.
endfunction

The usage of FirstOfGroup and group functions inside a loop is very common in AOE spells, with them we can do several things to a unit group.


Some tips with loops:
Sometimes, we want to use the loops as a way to do a mass effect spell. If you want to add special effects inside a loop, there is a big chance the code will lag, in order to avoid that, you should use a TriggerSleepACtion() function, which will give to the WC3 engine a small break to process other tasks.

You can create an infinite and unstopable loop using only the loop and endloop instructions without an exitwhen command.


Exercise:

Create a function which display all the numbers which can divide perfectly a given number. The function should be in that way:
Collapse JASS:
function DivideNumbers takes integer n returns nothing
    // your code here 
endfunction

For exaple, if we make DivideNumbers(12) we should see on the game screen something like this:

1, 2, 3, 4, 6, 12

Good luck :)
Attached Files
File Type: txt Tut4.txt (4.9 KB, 58 views)

Last edited by moyack : 12-25-2006 at 06:50 PM.
moyack is offline   Reply With Quote
Old 12-25-2006, 08:41 PM   #15
Av3n
Roar!
 
Av3n's Avatar


Project Leader: TBR
Project Member: PoC
 
Join Date: May 2006
Posts: 1,853

Submissions (7)

Av3n is a jewel in the rough (240)Av3n is a jewel in the rough (240)Av3n is a jewel in the rough (240)Av3n is a jewel in the rough (240)Av3n is a jewel in the rough (240)

Hero #4 extra-official winner2008 Spell olympics - Fire - BronzeHero Contest #3 - 3rd Place

Default

If I had time, i'll learn JASS straight away, with these, also merge posts as well.

-Av3n
__________________

Thanks to FatherTime for the sig
.:
Current ProjectsSubmissions
Power of CorruptionMy Terrain
The Black RoadMy Resources
Strikeforce
Twitter
Av3n is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 10:15 PM.


Donate

Affiliates
The Hubb http://bylur.com - Warcraft, StarCraft, Diablo and DotA Blog & Forums The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2014, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services