JASS: Moving From GUI to Jass, the Start

Tutorial By Rheias

Moving From GUI to Jass, the Start




0. Table of Content


0.1 Content

0.1.1 Introduction - An introduction to the tutorial and to the basics of Jass. I will explain here about the tutorial, what is it's goal and how I'm attempting to achieve it. Also a brief explanation of what Jass is and why it is better then GUI.
1.1 Introduction to the Tutorial.
1.1.1 Basic Review
1.1.2 The Tutorial’s Organization
1.1.3 Tutorial’s Explanation Process
1.1.4 Tutorial’s Requirements
1.1.5 How to read this Tutorial
1.1.6 Tags

1.1.6.1 Why use tags?
1.1.6.2 When will I use each Tag?

1.1.7 Updates
1.1.8 Final Notes

1.2 Introduction to Jass
1.2.1 What is Jass?
1.2.2 Why use Jass?
1.2.3 Writing Jass
1.2.4 Jass’ System

1.3 Conclusions
1.3.1 The Tutorial
1.3.2 Jass
1.3.3 Final words


0.1.2 Functions - Introduction to functions. What are they? How are they used and created? What are user-designed functions and native functions? What is the difference? Parameters? And more.
2.1 User-Defined function
2.1.1 Functions and GUI
2.1.2 Functions’ Goals
2.1.3 Creating a Function

2.1.3.1 Parameters’ Syntax
2.1.4 Functions as Blocks
2.1.5 Returning

2.2 Blizzard’s Functions
2.2.1 Blizzard Functions and GUI
2.2 Blizzard Functions and User Functions
2.2.3 Calling Functions

2.3 Conclusions
2.3.1 Conclude User-Defined Functions
2.3.2 Conclude Blizzard Functions
2.3.3 What next
2.3.4 Again, Calling
2.3.5 Functions in Math


0.1.3 Variables - A whole part dedicated to variables, how to use them, when, why. Globals, locals, comparisons, and setting them to new values.
3.1 Introduction to Variables
3.1.1 Variables in GUI
3.1.2 Variables in Jass
3.1.3 Warning

3.2 Global Variables
3.2.1 Using Global Variables
3.2.2 Globals in Jass
.2.3 Locals and Globals

3.3 Local Variable
3.3.1 Introduction to locals
3.3.2 Creating Locals
3.3.3 Setting Values
3.3.4 Comparisons

3.4 Conclude Variables
3.4.1 Globals and Locals
3.4.2 Variables in Jass


0.1.4 Special Actions - This chapter will talk about the special actions which are If / Then / Else and Loop orders. Those are two important actions, read about them in this chapter!

4.1 Introduction to Special Actions
4.1.1 What are Special Actions
4.1.2 The Dangers
4.1.3 Multiple Use

4.2 If / Then / Else
4.2.1 Introduction to If / Then / Else
4.2.2 If / Then / Else’s Syntax
4.2.3 Examples
4.2.4 Elseif
4.2.5 Uses of If / Then / Else

4.3 Loops
4.3.1 Introductions to Loops
4.3.2 Loops’ Syntax
4.3.3 Normal Loop
4.3.4 Other Loops

4.4 Special Actions Conclusions
4.4.1 Special Actions
4.4.2 Conclude If / Then / Else
4.4.3 Conclude Loops


0.1.5 What's Next? - Suggesting on how to keep learning Jass after this tutorial. Short part but does what it needs.


1. Introduction

Here you will find an introduction to the tutorial itself as a written script and to Jass. This is the least important part however I suggest reading it to make sure we are all on the same level before going into the tutorial itself. Skipping over this chapter could cause you to be confused later on. I HIGHLY suggest that you read the other tutorial I wrote, as it can ease your reading through this tutorial greatly, reading it first would make the learning path much shorter and easier to cross. Before Jass

1.1 Introduction to the Tutorial

1.1.1 Basic Review
This tutorial came to attempt to teach the basics of Jass. Indeed there are already tutorials on this, however in this one I’ll try to explain what other tutorials seemed to be a bit unclear. I’ll take other points of view in explaining and do my best to get you started with the basics of Jass.

1.1.2 The Tutorial’s Organization
The tutorial is divided into parts, chapters, sub-chapters, notes / lists & additions. The left integer presents the part’s number, then a dot and then the chapter’s number, after that the sub-chapter's number. Notes / lists & additions do not appear as a number.

Long additions may be expanded into sub-sub-chapters. If so, their number will be included.

Parts would be bolded and underlined (B and U) chapters bolded (B), sub-chapters underlined (U) and additions Italic (I).

1.1.3 Tutorial’s Explanation Process
Well, basically the way I will attempt to teach Jass in this tutorial is by constant reference to GUI. Each subject will be learned deeply and each subject will be reviewed and compared to a similar function in GUI. This way, the GUIers of you could read this tutorial more easily. This is what Daelin partly attempted to do in his tutorial, but I’ll take it one step forward and make the whole tutorial (or most of it) something sort of like Jass vs GUI.

Note: GUI is Graphical User Interface. Usually when working with triggers you are dealing with either Jass or GUI. Jass is the script language, while GUI uses charts to ease the working process with Jass (more of this later).

1.1.4 Tutorial’s Requirements

Well, there are none really I guess, you should have at the very least basic knowledge of GUI, no need for more than that. The tutorial is in English, so obviously you need to know how to speak English well. Oh, and a common sense wouldn’t hurt, I would hate answering questions such as, “Why is the tutorial so darn long?”

1.1.5 How to read this Tutorial

There is not doubt this is a long, tiring tutorial (believe me writing it was hard as well ;-) ) this is why I organized it into so many parts, chapters and sub-chapters, you can easily stop somewhere, take a rest, and then continue from the same place. All you’ll need to do is to look at the chapter’s headers to remember what was discussed already and you are good to go.

I do not recommend reading this whole tutorial at once, it is long, hard to read and generally tough; take few rests between the chapters, that way you could let the information “sink into your brain” better.

Also I suggest reading everything, skipping on something might make it harder for you to understand the rest of the tutorial. If you really don’t want to read something, because you don’t think it is important enough or something like that, at least read the conclusion at the end of every part.

1.1.6 Tags

While reading this tutorial you will meet 2 type of tags, code tags and Jass tags, both will be used in order to represent codes and functions.

Hello, I’m a Jass tag, how are you?


Look, I’m a talking code tag!

1.1.6.1 Why use tags?

Tags allow me to represent the tutorial in a clearer way for you to read. First it distinguishes between a code and the tutorial which will usually include explanation. Secondly tags allow me to write long lines without expanding the page’s width, so you will not have to keep scrolling to the sides. Example:

This is a really long line. Am I talking about anything here? No this is just an example, isn’t it? Well let’s just see what happens when this gets really long… Ok this is long enough!

Finally, when using tags I can put spaces before the line, this will make the presentation clearer.

          So many spaces. Wow! 
                                                              And few more.
                                                                                                      You got the idea I hope?


1.1.6.2 When will I use each Tag?

I will use Jass tags to represent most of the functions and Jass scripts in the tutorial. Code tags will be used in order to represent GUI codes and Jass codes where certain lines will need to be highlighted.

1.1.7 Updates

Each update will be recorded here, also I will bump this thread when any update occurs. Note that I will record only major updates, fixing something like “jsut” to “just” will not be recorded. If I will fix many spelling / grammar record then I will state something like: “update: major grammar and spelling fixes”


Current Version: 1.0

Version 1.0
- First release of the tutorial



1.1.8 Final Notes

Here is list that includes a few final notes about the tutorial.


• English is not my native language; I should note that at first. I’m using a dictionary and a spell checker, so most errors should be fixed however if you spot any problems please know that it was made out of ignorance and not out of laziness to re-read the tutorial (actually I read every part about 3 times). If you find a critical error I would appreciate it if you would point it out.


• I would love to hear comments about the tutorial, negative, positive, whatever, any comments would be great. However, I worked very hard on this tutorial, so if your feedback is negative, try to put it politely please. If you have any questions please do ask them.


• If during the tutorial you don't understand something, don't be frustrated, Jass is hard to learn and for some people it is harder to than for others. Re-read whatever you don't understand, and if you still don't understand skip it and return to it after finishing with the tutorial. I also strongly suggest to read this tutorial at least twice to make sure you understood everything completely.


• I worked on this tutorial about a month, so, take that into account when commenting… I don’t mean to say you must say this is a wonderful tutorial, but try not mocking me by saying “This tutorial sucks!” etc. If you learned something from it, appreciation post could only make me feel better. ;)


• The tutorial is broken into several parts because it is too long for thehelper.net to store it in only one post, so I had to divide it into few posts, sorry about that!


1.2 Introduction to Jass

Here is a brief explanation of what Jass is. Most of the things I will talk about are technical; I will not talk yet on how Jass really works. Also, since I did this in another tutorial of mine, please excuse me if I quote myself, I simply have already put it in a clear way, no need to fix what works fine.

1.2.1 What is Jass?

Quoted from Before Jass.


Like any other software, World Editor needs to read script to know what to do, everything else but the script is simply to ease the script writing. So, for example, when you are making “regular” trigger you use Graphical User Interface (known as GUI). What World Editor does is convert your triggers (and everything else, but that’s something else) into script and then reads it. Do you want a proof? Fine, create a new trigger and do something with it. Say create a trigger that will create a footman in the middle of the map for player red every second. Now select the trigger, go to Edit > Convert to text and see what you get, that’s Jass. This is the true scripting language of World Editor, whenever you work with GUI it is converted to the text you see here, and then when playing your map, Warcraft’s engine can read it.


In other words we can say the World Editor must take script in order to execute orders. When we are working with GUI (normal triggers) World Editor takes the data given, converts it into Jass, and then works from there. Let’s create a simple trigger together, something like this:

Untitled Trigger 001 Events Time - Every 2.00 seconds of game time Conditions Actions Special Effect - Create a special effect at (Center of (Playable map area)) using Abilities\Spells\Human\ThunderClap\ThunderClapCaster.mdl

This trigger will basically create a special effect in the middle of the map every 2 seconds. Now select the trigger you created and go up to edit. In edit go and click on Convert to Custom Text.

(Image)

A warning message will appear on the screen saying that the trigger could not be converted back into GUI. Actually you can convert it back to GUI by pressing on Ctrl + Z but that doesn’t matter at the moment. Now you should be able to see this text:

function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
    call AddSpecialEffectLocBJ( GetRectCenter(GetPlayableMapRect()), "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl" )
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_001 = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Untitled_Trigger_001, 2 )
    call TriggerAddAction( gg_trg_Untitled_Trigger_001, function Trig_Untitled_Trigger_001_Actions )
endfunction


This is Jass, looking like gibberish? It should at the moment, don’t worry. By the end of the tutorial you should be able to understand it.

So, as you can see, GUI is converted to Jass, and we can say that Jass is World Editor’s true scripting language, and GUI is nothing but a tool to edit it.

1.2.2 Why use Jass?

Again, allow me to quote myself from my tutorial Before Jass.



Typing is faster then clicking - It was tested and proven that it is faster to write in the computer then to use your mouse and clicking it. So technically Jass is faster to use, because you write scripts. In GUI however, you use charts and click on your picked values.


Jass can do more things - In Jass there are functions (events / conditions / actions) which you can’t find in GUI. Blizzard didn’t convert all of its functions into GUI from Jass because a few were unsafe, or simply Blizzard thought they weren’t needed.


Jass’ functions are faster - Not only that Jass has more functions, but usually when working with Jass you use natives functions (certain types of functions) which are fast, while in GUI usually you work with BJs (other type of functions) which are slower then natives.


Jass does things faster - Not only are Jass’ functions faster, but Jass can also do things faster. Because of the clumsy way GUI is organized, everything is limited, however in Jass because of the flexible system you can do things with many fewer lines and functions calls. Also because of that it is faster to write Jass (well at least after you are familiar with it).


Jass takes less memory - Well this is hardly noticeable, but yes, Jass takes less memory space, especially because it uses locals and not globals. Also with Jass you can remove all leaks, while in GUI you can remove none (well you can remove some by using Custom Script, but not all even with that).


Jass is MUI - Because Jass uses local variables (a special kind of variable) you can easily create MUI spells and triggers with it.


Better Loops - Jass’ loops are much more flexible like most things in Jass and allow us to have complete control over them and use them in the best way possible.


Systems with Jass - Most of the systems now days (or at least the more advanced ones) use Jass, not only because it is easier to work with Jass but because systems can be used the best with Jass only (we can call new user defined functions with Jass ).


Jass is easier to read - Once you know Jass well enough it is easier to read, and to edit than GUI, it makes sharing of triggers, spells and systems easier and better.


People use Jass - People move to Jass. Lately many tutorials were written that ease the learning by much, so many people decide they can spend the time on learning Jass and work with it, you wouldn’t want to stay with GUI while the rest of the mappers make products for Jass.


Jass is powerful - Finally, most of the interesting finds about World Editor are about Jass, GUI is too simple to work on, however some amazing stuff was discovered about Jass that completely changes the programming experience. For example the return bug (well now few problems were found with it but oh well), using conditions as actions and many more things that relate to Jass but not at all to GUI.



So we can assume that Jass is better than GUI from those finds I guess. The real question that you should be asking yourself is if it’s worth putting all this effort to learn Jass. Well, as shown, Jass is by far better than GUI, if you have the time to learn Jass, you should learn it, no doubts. Few people feel like they want to master GUI completely before moving to Jass. That’s fine, GUI can be learned in less than a month, and after that in order to advance you’ll need to learn Jass.

1.2.3 Writing Jass

There are few ways to write Jass, each one has its own upsides and downsides.



• World Editor - As you can see you can convert triggers into custom text in World Editor by selecting them, and then going to edit and convert to custom text (see the image above). Well you can convert an empty trigger to Jass and start working from there.
Upsides: World Editor gives you the basic functions; without them you need to keep rewriting them. Also you can test your trigger much more easily.
Downsides: There are 3 problems with World Editor’s syntax checker. A) It is stupid. B) It returns false errors, and even the true errors it can't put clearly. C) Little mistakes may cause it to crash.


• Notepad - The simplest answer, you don’t need to down anything, just open notepad and start working. Don’t use “Word” though, because it’s pages’ length is limited, notepad’s pages can get very wide.
Upsides: You don't have to deal with annoying World Editor, and nothing needs to be download, just get into notepad and start working!
Downsides: No way to know easily if you have errors in your script, plus it might look unclear and plain.


• Software - There are few programs out there that can aid you in scripting in Jass.
TESH - A nice add-on to World Editor, makes it easier to work with it, however I found it a bit buggy. Warmly suggested if you don’t want to keep switching between two windows.
JassCraft - My favorite tool, everything you need comes with it: colored text, accurate errors finder (more or less), function list and detailed information about functions. There are few others programs, but they similar to those two. Jass Shop Pro or Jass Editor are 2 other possible programs for you to use.
Upsides: It really depends on what program you are using, but they usually come with a lot to help you with, such as colored text, better errors finder, list of functions and so on...
Downsides: None really, the only thing that might irritate you a bit is the fact that you’ll need to keep switching between your program’s window and World Editor’s window.


1.2.4 Jass’ System

Now we start talking seriously, all of this was merely an introduction. Let’s examine a second trigger in GUI. GUI’s triggers are made of events, conditions and actions. Once any of the events is met the trigger will run, if all the conditions are met the trigger will precede to the actions part, which is the main part of the trigger and will do something. For example this trigger:

Untitled Trigger 001 Events Unit - A unit Is attacked Conditions (Unit-type of (Triggering unit)) Equal to Peasant Actions Unit - Kill (Triggering unit)

This is pretty clear, the event is that a unit is attacked, the condition is that it’s a peasant so the trigger will only run if it is a peasant and the action is to kill the attacked unit. Jass is not made of actions, conditions and events but from functions. Each function can do anything really. It can be an action or part of it, Boolean or Boolean expression, something that returns an integer, a function that will do something to a given group… Anything really. This makes Jass much more flexible, because we don’t have the usual order of event, condition & action but function, function and & function, each one of those can do about anything I tell it. In other words:


GUI is made out of events, conditions and actions, and those three are stored inside a whole trigger which stores them all. That’s why GUI is so easy to edit and work with, but it makes it very limited. Jass is made out of functions, each function can serve as event, condition, action, part of one of those three, or something else completely. This makes the working process faster, easier and more flexible.


1.3 Conclusions

A quick conclusion of this part.

1.3.1 The Tutorial

The tutorial is made to help you learn the basics of Jass while continuing to compare it to GUI. The tutorial is divided into many parts, chapters and sub-chapters to make the reading process easier.

1.3.2 Jass

Jass is the source language of World Editor and GUI is nothing but a tool to help us edit Jass. GUI will be converted to Jass so the game can read it; however by working directly with Jass we benefit a lot more. The way Jass works is from many functions that can be formed into many triggers, systems, spells etc.

1.3.3 Final words

Final words before the (long) introduction ends:

I hope you will enjoy this tutorial I worked on this very hard to try and teach you this stuff so please take that into consideration. All questions and comments are more than welcomed.

I hope you enjoy your reading, or at least learn something from it!

Tutorial’s author: Rheias.

The tutorial itself is in the second post, so keep reading. Credits to Ghan_04 for fixing grammar mistakes.

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.