• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Magic of JASS [Reviewed: Ghan_04]

Level 9
Joined
Apr 14, 2008
Messages
192
Magic of JASS

Jass can do many things for you. But what i find is that JASS is more
easy to learn than normal triggering.

JASS may seem hard to learn but its not you can aculy learn it very easy. I will
show you some code's and JASS scripts that show you what they do and how small they are. If you will like to learn JASS please contact me and i will send you a 2 page JASS learning Tutorial.


Sample code

The following function creates a string containing the message "Hello, world!" and displays it to all players:

JASS:
function Trig_JASS_test_Actions takes nothing returns nothing
 call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "Hello, world!")
endfunction
or if you want this only for one player:

JASS:
function Trig_JASS_test_Actions takes player p returns nothing
 call DisplayTextToPlayer(p, 0,0, "Hello, world!")
endfunction
And if you want to print the message 100 times and show the iterator:

JASS:
function Trig_JASS_test_Actions takes player p returns nothing
 local integer i=0
 loop
   exitwhen i==100
   call DisplayTextToPlayer(p, 0,0, "Hello, world! "+I2S(i))
   set i=i+1
  endloop
endfunction



Here is some more stuff that has got to do with JASS codeing:

My target is to make a practical JASS course, since there are already plenty of theorical tutorias. I will purposely skip some stuff, remember that this is just to start in JASS, and after that you will have to see Open source JASS scripts and other Tutorials.

The only thing I will require for you is that you should already know how to extract files from a MPQ , search for that in the forums or google. But I don't want to ellaborate on that.

The first step is to open World Editor, create a new map and then open the trigger editor, select the trigger 'Map initialization' and you will most probably see this:


  • Melee Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Melee Game - Limit Heroes to 1 per Hero-type (for all players)
      • Melee Game - Give trained Heroes a Scroll of Town Portal (for all players)
      • Melee Game - Use melee time of day (for all players)
      • Melee Game - Set starting resources (for all players)
      • Melee Game - Remove creeps and critters from used start locations (for all players)
      • Melee Game - Create starting units (for all players)
      • Melee Game - Run melee AI scripts (for computer players)
      • Melee Game - Enforce victory/defeat conditions (for all players)
Now we will have to set the battle field ready for battle, change the Event to A Player skips a cinematic, remove the actions and replace them with a text message action. Rename the trigger to JASS test.

JASS:
JASS test
    Events
        Player - Player 1 (Red) skips a cinematic sequence
    Conditions
    Actions
        Game - Display to (All players) the text: This is a message
Time to get started, go to the edit menu and Convert It to custom text. press OK.

JASS:
function Trig_JASS_test_Actions takes nothing returns nothing
    call DisplayTextToForce( GetPlayersAll(), "TRIGSTR_004" )
endfunction

//===========================================================================
function InitTrig_JASS_test takes nothing returns nothing
    set gg_trg_JASS_test = CreateTrigger(  )
    call TriggerRegisterPlayerEventEndCinematic( gg_trg_JASS_test, Player(0) )
    call TriggerAddAction( gg_trg_JASS_test, function Trig_JASS_test_Actions )
endfunction
The first obstacle, what happened to the "This is a message" text?

TRIGSTR_004 , reffers to a string in war3map.wts (the map strings) you are able to edit that file with the World Editor's File\Export/Import Strings... commands. But for practical reasons we will forget about that and just use the text we like.


JASS:
function Trig_JASS_test_Actions takes nothing returns nothing
    call DisplayTextToForce( GetPlayersAll(), "This is a message" )
endfunction

//===========================================================================
function InitTrig_JASS_test takes nothing returns nothing
    set gg_trg_JASS_test = CreateTrigger(  )
    call TriggerRegisterPlayerEventEndCinematic( gg_trg_JASS_test, Player(0) )
    call TriggerAddAction( gg_trg_JASS_test, function Trig_JASS_test_Actions )
endfunction

Here we will see 2 functions , Trig_JASS_test_Actions and InitTrig_JASS_test.

Each "Trigger" in the Trigger editor comes with a InitTrig_TRIGGERNAME (Spaces are replaced with _) function that is always called at the initialization of the map.

In this case we are talking about the InitTrig_JASS_test function. In the contents of that function we will see these lines:


Code:
set gg_trg_JASS_test = CreateTrigger(  )
    call TriggerRegisterPlayerEventEndCinematic( gg_trg_JASS_test, Player(0) )
    call TriggerAddAction( gg_trg_JASS_test, function Trig_JASS_test_Actions )
For now we will say they are the Setup of a trigger that is saved under the gg_trg_JASS_test variable. A line to highlight is

JASS:
call TriggerAddAction( gg_trg_JASS_test, function Trig_JASS_test_Actions )
It says that the action function for the gg_trg_JASS_test trigger is Trig_JASS_test_Actions. So for now the only thing we will do is editing the contents of that function , keep the other function with no changes.

We are now ready to start the course!

1. First Saving.

Save the map, it shouldn't give you errors unless you made a major mistake when replacing the contents of the message, double check it.

Most likely the message MUST be between quotes "" .


If it doesn't give you errors, Test the map using the Test Map button.

Now in game press Escape, it should show the "This is a message" text. This is the way we will test JASS for now.

2. Variables Tests

The syntax for making a local variable inside a function is the following:

local <VARIABLE TYPE> <VARIABLE NAME>

Optionally you can initiate the local variable with a value


local <VARIABLE TYPE> <VARIABLE NAME> = value

Variable names should not start with a number, and may only have alpha numeric characters and _


Strings
The first type we will use is string , a string is just text between "". The syntax does not care about what you use inside the string.

We will call the variable "a" .


It is time to say that JASS is case sensitive, so typing A is not the same as typing a , you can't use LOCAL nor Local for the declaration of the variable, you must use local.


JASS:
function Trig_JASS_test_Actions takes nothing returns nothing
 local string a="This is a message"
    call DisplayTextToForce( GetPlayersAll(), a )
endfunction
In the example we just moved the message to the value of the variable named "a". When we used the variable in the Function that shows the message we didn't put it inside "".

Test the map, it should work the same way it worked before.

You can have multiple variables inside a function, but always make sure the declaration of the variables is before any other line.



JASS:
function Trig_JASS_test_Actions takes nothing returns nothing
 local string a="This is a message"
 local string b="This is other message"
    call DisplayTextToForce( GetPlayersAll(), a )
endfunction
What's the point of having 2 variables if we don't use the second one? Let us copy the Message function call to create another one. Then replace a with b

JASS:
function Trig_JASS_test_Actions takes nothing returns nothing
 local string a="This is a message"
 local string b="This is other message"
    call DisplayTextToForce( GetPlayersAll(), a )
    call DisplayTextToForce( GetPlayersAll(), b )
endfunction
When you test the map it will show both messages.
 
Last edited:
Level 22
Joined
Feb 26, 2008
Messages
892
I kind of feel like this tutorial is not as helpful as it may seem on the surface. It just feels to me like you are saying, "Here! Use this block of code to do this!" I don't feel like someone reading this tutorial would get a good bit of useful knowledge out of this kind of a tutorial.


Some suggestions for improvement:

1. Spellcheck
2. You have some problems with the [CODE] tags; please check that. Also, use [TRIGGER][/TRIGGER] tags for GUI triggers.
3. Talk more about concepts. Your statements don't teach anyone anything unless they can understand WHY. I think you need more explanation.
 
Top