World of Warcraft
Starcraft
Warcraft 3
Starcraft 2

War3map.j

From Source Peek Wiki

Jump to: navigation, search

The JASS2 Script

This is the main map script file. It's a text file and you can open it with notepad. The language used is called JASS2 and has been developped by Blizzard. It's a case sensitive language.

When you play a map, the jass script is loaded and executed. To run it, Warcraft III looks for the function called "main".

The language uses several keywords as described here:

Keyword Description
function used to define a new fonction
takes used to define the number of arguments for a fontction
returns sets the type of the value returned by a function
return makes a function leaves and returns a value
endfunction ends a function definition
call used to call a function that returns nothing
globals used to define the list of global variables
endglobals ends the list of global variables definition
local defines a local variable
set assigns a value to a variable
if, elseif, else, then, endif if (...) then ...
elseif (...) then ...
else ...
endif

Just an "if-then-else-endif" chain like in Basic.
loop, exitwhen, endloop used to make loops in the script
constant defines a constant
type defines a new type/class
extends says what the mother type is
native defines a function header of an external built-in function implemented in Game.DLL

Only two "native types" exists: "nothing" and "handle". All the other types are derived (keyword "extends") from "handle". You can get the full list of types and native functions from the file called "Scripts\Common.j" in your War3.mpq file. You can assign several types of constant values to the handle type: a generic null value called "null", any interger, any float, any string or trigger string, "true" and "false".

Here is the list of operators recognized by the language:

Operator Description
( ) parenthesis for priorities
+ addition (concatenation for strings)
- substraction
* multiplication
/ division
= assignation
= =, <, <=, >, >=, != comparison (equal, lighter, lighter or equal, greater, greater or equal, different)
not invert a boolean value

The functions used by the World Editor are defined in "Scripts\Blizzard.j". Example of a function definition:

    function myfunction takes nothing returns integer
       local string str = "blah blah blah"
       local integer i
       // comments line
       set i = 0
       loop
          set i = i + 1
          if (i == 27) then
             call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, str)
          endif
          exitwhen i == 30
       endloop
       return i
    endfunction
This page was last modified on 22 April 2008, at 21:37. This page has been accessed 640 times.