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.
__________
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:
Example:
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:
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:
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:
__________
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:
Example:
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:
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:
This text macro will create two functions:
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:
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:
This would display "Hello!".
Syntax:
Create a struct:
Destroy a struct:
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:
Here's another example:
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:
To call a method:
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.
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.
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:
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:
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:
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:
__________
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:
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:
This text macro will create two functions:
JASS:
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$), "asdf", true )
//! endtextmacro
//! runtextmacro chat("0")
//! runtextmacro chat("1")
//! runtextmacro chat("2")
//! runtextmacro chat("3")
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 = "Hello!"
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:
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:
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;A000039;
endfunction
function Trig_Spell_Timeout takes nothing returns nothing
local timer t = GetExpiredTimer()
local spell data = spell(GetHandleInt(t,"struct"))
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,"struct",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.