JASS - vJASS (Light)

1

1337D00D

Guest
Whoops, Mod please renaname title to vJass, i messed up.

This is a tutorial on how to use some of the advanced JASS functions provided by vJass.

Stop! If you are not using the JASS NewGen Pack, don't bother reading this tutorial!

This tutorial will cover how to use:
Libraries
Scopes
Text Macros
Structs
<More later>

__________


Globals

You are able to use global blocks almost anywhere now.

JASS:
globals
	integer val = 0
endglobals


__________



Libraries

Libraries are groups of functions that will be placed before any others in the map script. Useful if you have a function that is called by others.

Syntax:
JASS:
library NAME [requires LIBRARY] [initializer FUNCTIONNAME]
...
endlibrary


Example:
JASS:
library mylib
	function libfunc takes nothing returns nothing
	endfunction
endlibrary


libfunc() will be loaded before any other functions.

Library Requirements


Sometimes functions within libraries will need to be placed before other libraries. In this case, you use the "requires" parameter. The library name given here will be placed before this library.

Example:
JASS:
library liba requires libb
	function libaf takes nothing returns nothing
		call libbf()
	endfunction
endlibrary

library libb
	function libbf takes nothing returns nothing
	endfunction
endlibrary


liba requires libb, so libb will be put before liba.
Note that you cannot have two libraries require each other.

Library Initializers


In cases where you need a function to be run before a certain library is loaded, use the "initializer" parameter. The function specified must take nothing.

Example:
JASS:
function init_liba takes nothing returns nothing
endfunction

library liba initializer init_liba
	function run takes nothing returns nothing
	endfunction
endlibrary


Library Private


Functions within libraries can be labeled as "private". Functions that are private are only used within their library. Functions outside the library can have the same name as the private one. Useful if there are multiple functions with similar names.

Only functions within the library are able to call to that function.

To make a function private, simply add "private" before the "function" declaration.
Example:
JASS:
library whee
	private function test takes nothing returns nothing
	endfunction
endlibrary

function test takes nothing returns nothing
endfunction


__________



Scopes

Scopes are similar to libraries, though they don't put the contained code at the top. Useful if you want to have private stuff.

Syntax:
JASS:
scope NAME
...
endscope


Example:
JASS:
scope myscope
	function scopetest takes nothing returns nothing
	endfunction
endscope


Scope Private

Same as Library Private

__________




Text Macros

This is something for all you lazy people. Textmacros allow you to make similar copies of other functions.

Syntax:
JASS:
//! textmacro NAME [takes ANYTHING,ANYTHING,...]
	function...
	...
	endfunction
//! endtextmacro
//! runtextmacro NAME(PARAMETERS)


The text macro will replace $ANYTHINGS$ with whatever value you give it when you run it. It's kind of hard to understand, so look at the example.

Example:
JASS:
//! textmacro dofunc takes FUNC,INSTANCE
function do$INSTANCE$ takes nothing returns nothing
	call $FUNC$
endfunction
//! endtextmacro
//! runtextmacro dofunc(&quot;DoNothing()&quot;,&quot;1&quot;)
//! runtextmacro dofunc(&quot;BJDebugMsg(\&quot;HI\&quot;)&quot;,&quot;2&quot;)


This text macro will create two functions:

JASS:
function do1 takes nothing returns nothing
	call DoNothing()
endfunction
function do2 takes nothing returns nothing
	call BJDebugMsg(&quot;HI&quot;)
endfunction


The parameters this text macro takes are FUNC and INSTANCE. Whatever you put as INSTANCE will be appended to "do". This is required, for if you left this part out it would create two functions with the same name.

Here's another example:
JASS:
//! textmacro chat takes num
call TriggerRegisterPlayerChatEvent( gg_trg_Untitled_Trigger_001, Player($num$), &quot;asdf&quot;, true )
//! endtextmacro
//! runtextmacro chat(&quot;0&quot;)
//! runtextmacro chat(&quot;1&quot;)
//! runtextmacro chat(&quot;2&quot;)
//! runtextmacro chat(&quot;3&quot;)


Here, you don't have to copy the whole line of code over and over again, just 0,1,2, and 3.

__________



Structs

Structs allow JASS to become more object-oriented. Kind of like Javascript or PHP class.

Example:
JASS:
struct somestruct
	string message = &quot;Hello!&quot;
endstruct

function showmsg takes nothing returns nothing
	local somestruct s=somestruct.create()
	call BJDebugMsg(s.message)
	call s.destroy()
endfunction


This would display "Hello!".

Syntax:
JASS:
struct NAME
...
endstruct


Create a struct:
JASS:
	local STRUCTNAME VARIABLENAME=STRUCTNAME.create(ARGS)


Destroy a struct:
JASS:
	call VARIABLENAME.destroy()


Note that you need to destroy structs when you're done with them. There's a limit of 8190 undestroyed structs at one time.

In order to get a variable within a struct:
JASS:
	VARIABLENAME.VARIABLEINSIDEOFSTRUCT


Here's another example:
JASS:
struct test
	real one=1
	real two=2
	real three=3
	real sum
endstruct

function add takes nothing returns nothing
	local test blah=test.create()
	set blah.sum=blah.one+blah.two+blah.three
	call BJDebugMsg(R2S(blah.sum))
	call blah.destroy()
endfunction


The above function will display "6.000".

Note that you don't need to null struct variables.
Structs also cannot have arrays in them.
Structs also instance themselves, so you can have two of the same structs out at the same time.

Struct Methods


Methods are functions within structs. That's it.

Example:
JASS:
struct we
	string msg=&quot;Hello!&quot;
	method sayit takes nothing returns nothing
		call BJDebugMsg(this.msg)
	endmethod
endstruct

function test takes nothing returns nothing
	local we s=we.create()
	call s.sayit()
	call s.destroy()
endfunction



To call a method:
JASS:
	call VARIABLENAME.METHOD(ARGS)


Note inside the "sayit" method, I used "this.msg". To get a variable inside the same struct, use "this.".

Don't use GetTriggeringTrigger() or waits inside methods.


You can use structs to almost completely replace local handle variables.

JASS:
struct spell
	real x
	real y
	unit target
endstruct

function Trig_Spell_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == &#039;A000&#039;
endfunction

function Trig_Spell_Timeout takes nothing returns nothing
	local timer t = GetExpiredTimer()
	local spell data = spell(GetHandleInt(t,&quot;struct&quot;))
	call SetUnitPosition(data.target,data.x,data.y)
	call data.destroy()
	call PauseTimer(t)
	call FlushHandleLocals(t)
	call DestroyTimer(t)
	set t=null
endfunction


function Trig_Spell_Actions takes nothing returns nothing
	local spell data = spell.create()
	local unit u = GetSpellAbilityUnit()
	local unit ta = GetSpellTargetUnit()
	local timer t = CreateTimer()
	set data.x = GetUnitX(t)
	set data.y = GetUnitY(t)
	set data.target = ta
	call SetHandleInt(t,&quot;struct&quot;,data)
	call TimerStart(t,GetRandomReal(0,10),false,function Trig_Spell_Timeout)
	set u=null
	set ta=null
	set t=null
endfunction

//===========================================================================
function InitTrig_Spell takes nothing returns nothing
    set gg_trg_Spell = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Spell, EVENT_PLAYER_UNIT_SPELL_FINISH )
    call TriggerAddCondition( gg_trg_Spell, Condition( function Trig_Spell_Conditions ) )
    call TriggerAddAction( gg_trg_Spell, function Trig_Spell_Actions )
endfunction


This spell teleports the target unit back to its original position after a random number of seconds. This spell only uses local handle variables once, and is much faster because structs are faster than using GameCaches.





__________

More to come soon, this is a W.I.P.
 

substance

New Member
Reaction score
34
Im thinkin this should go in the JASS section?

Hmm, a very short explaination of vJass, but a explanation nonetheless. Maybe you should show each example in practical use? Either way, I'm happy to see the sight of vJass growing in this community.
 

Sooda

Diversity enchants
Reaction score
318
> [Tutorial WIP]

He is updating it more.

Some full working examples how to move/ use structs would be nice. It' s small but lets hope it will be useful. I' m waiting for this kind of tutorials.
 
1

1337D00D

Guest
**Updated with an example of struct usage and a few random other stuff.
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
Great job!

Can you give a quick list of the rest of the features in NewGen pack? You don't have to explain them, just the names so I'll know what to look for. ;)

Thanks.
 

waaaks!

Zinctified
Reaction score
255
i was reading the system in the map made by vex, what is that again? is the map in a frost island were you must survive, and i found some functions like libraries, structs, and scope, and i didnt understand any of those, now that you made this, ill understand it first and make my own libraries....i can say this tut must be in the tutorial submission, so that people can also make their own libraries structs and scopes....nice tut, but i cant rep you....
 

emjlr3

Change can be a good thing
Reaction score
395
not too indepth, but it gets the job done, keep it updated

moved
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
1337D00D doesn't come on anymore. I saw this tutorial a long time ago when he posted it, it made me have a better knowledge of vJASS. Gj 1337.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top