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.
  • Varine Varine:
    I ordered like five blocks for 15 dollars. They're just little aluminum blocks with holes drilled into them
  • Varine Varine:
    They are pretty much disposable. I have shitty nozzles though, and I don't think these were designed for how hot I've run them
  • Varine Varine:
    I tried to extract it but the thing is pretty stuck. Idk what else I can use this for
  • Varine Varine:
    I'll throw it into my scrap stuff box, I'm sure can be used for something
  • Varine Varine:
    I have spare parts for like, everything BUT that block lol. Oh well, I'll print this shit next week I guess. Hopefully it fits
  • Varine Varine:
    I see that, despite your insistence to the contrary, we are becoming a recipe website
  • Varine Varine:
    Which is unique I guess.
  • The Helper The Helper:
    Actually I was just playing with having some kind of mention of the food forum and recipes on the main page to test and see if it would engage some of those people to post something. It is just weird to get so much traffic and no engagement
  • The Helper The Helper:
    So what it really is me trying to implement some kind of better site navigation not change the whole theme of the site
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top