Cohadar
master of fugue
- Reaction score
- 209
I will now demonstrate how to switch from GUI to vJASS.
For those of you who think that it might be better to first learn JASS and then go for vJASS - you are wrong.
This is jass:
This is vJASS:
First thing you notice is that jass does not have colors, this is only one of many reasons jass sux.
So lets all just forget about old rusty jass and go straight for vJass.
First of all you will need to download and learn how to use NewGen
It's all explained there.
When you download NewGen try to compile some of your GUI maps with it,
when you do it, come back here.
//===========================================================================
Now lets try converting some triggers from GUI to vJASS
Before we continue remember this:
Ok lets look at a simple GUI trigger:
When hero dies, revive him instantly at center of map.
This trigger might be simple but it has all we need, it has an Event, an Action and a Condition.
Lets see how it looks when we convert it to text:
(Select the trigger and go to Edit->Convert to Custom Text)
It looks ugly doesn't it?
Well check this out: WE does not know how to generate vJASS, what you are actually looking at is old stupid jass.
So all you can do is convert GUI to jass, if you want vJASS you have to do it yourself.
//===========================================
The First thing we need to do is put a scope around that jass to make it vJASS:
Advice: Making scope name same as your trigger name will save you a lot of trouble when hunting for errors.
There is one problem here. vJASS cannot have spaces or underscores in scope names (jet). So you will have to rename your triggers from:
"Do Some Stuff" to "DoSomeStuff"
//===========================================
Lets see how stupid WE generates code:
It converted this:
to this:
But we will convert it to vJass now:
Who's my pretty boy
As you can see vJASS pwnz GUI generated jass.
//===========================================
Ok lets do the action now:
jass:
vJASS:
Ok what happened now?
First of all we removed the whole GetRectCenter(GetPlayableMapRect()) thing.
We know that center of map is (0, 0) so instead of using ReviveHeroLoc we use ReviveHero function
{this also prevented location leak }
Ok but where did ReviveHero function come from?
How did I know what are it's arguments? Omg cohadar knows all jass functions :nuts:
Not even close.
What I know is how to use function list:
It is a cool feature in vJASS TESH editor,
you just type in few letters and it lists all functions that have that letters in name.
So it is even easier than finding functions inside GUI editor lists.
There is also a cool feature called autocompletion.
You type in a few first letters of a function inside a trigger: Rev
and a small pop-up window appears telling you what could be proper function names.
Damn this vJASS shit is easy.
But wait, it gets even better.
You type in the function name and a first bracket: ReviveHero(
and it pops up again showing you the arguments of the function.
Omg this vJASS shit is easier than GUI.
//========================================================
Lets get back to our trigger, we have one more thing to change, this:
Ok where did this come from, there was no such thing in GUI?
Actually there was, it is the event:
+ connecting all together.
Lets convert this to vJASS before we continue:
Create the trigger:
Add event to the trigger:
Add condition to the trigger:
Add action to the trigger:
So basically what Init does here is connects unit dies event with our functions.
Very important: vJass does not automatically know what is triggers InitTrig function so you have to specify it after scope declaration.
This whole Init part might sound complicated but the fact is you don't have to learn it.
What you do is create a simple trigger with only an event:
For example spell effect:
Convert it to jass:
and then to vJASS:
And than simply code the spell.
You do not have to remember how to do the whole TriggerAddCondition( trig, Condition( function Conditions ) ) stuff.
//======================================================
I attached a map with 2 simple triggers. Triggers are in GUI.
Your job is to convert them to vJASS as a practise.
All info you need to do that is in this tutorial,
and if you bump into any problems came here and tell us about it.
//======================================================
You might have noticed that a lot of things in this tutorial are not explained,
what is a scope, what is public, what is private?
why you change things the way you do?
This tutorial was meant to show you how to start coding vJASS the quickest way possible.
In order to learn why things are done they way the are,
and what do they mean you will have to learn yourself.
I do not believe that vJASS can be learned from tutorials,
you will simply have to code in vJASS every day and learn how and why to do things every day.
That is how you learned GUI didn't you?
//======================================================
TIP: There is a file jasshelper.html somewhere in NewGen directory, find it.
WARNING: When using NewGen always save map before you test it or it will not work.
ADVICE: Keep practising.
For those of you who think that it might be better to first learn JASS and then go for vJASS - you are wrong.
This is jass:
Code:
//===========================================================================
function InitTrig_HeroDiesJ takes nothing returns nothing
set gg_trg_HeroDiesJ = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_HeroDiesJ, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition( gg_trg_HeroDiesJ, Condition( function Trig_HeroDiesJ_Conditions ) )
call TriggerAddAction( gg_trg_HeroDiesJ, function Trig_HeroDiesJ_Actions )
endfunction
This is vJASS:
JASS:
//===========================================================================
private function Init takes nothing returns nothing
local trigger trig = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition( trig, Condition( function Trig_HeroDiesJ_Conditions ) )
call TriggerAddAction( trig, function Actions )
endfunction
First thing you notice is that jass does not have colors, this is only one of many reasons jass sux.
So lets all just forget about old rusty jass and go straight for vJass.
First of all you will need to download and learn how to use NewGen
It's all explained there.
When you download NewGen try to compile some of your GUI maps with it,
when you do it, come back here.
//===========================================================================
Now lets try converting some triggers from GUI to vJASS
Before we continue remember this:
You will NEVER be able to convert all GUI triggers in your map to jass,
it is impossible, GUI code generator is ugly like hell, it makes a ton of unnecessary gibberish and above all it does it with BJ's
GUI also mainly uses globals, while in jass you use locals.
Differences are simply too big, so basically GUI to JASS conversion is practically impossible for triggers longer than 5 actions.
Once you learn enough jass do NOT waste your time converting old GUI triggers, instead write them again in jass starting from zero.
It will be faster and easier.
it is impossible, GUI code generator is ugly like hell, it makes a ton of unnecessary gibberish and above all it does it with BJ's
GUI also mainly uses globals, while in jass you use locals.
Differences are simply too big, so basically GUI to JASS conversion is practically impossible for triggers longer than 5 actions.
Once you learn enough jass do NOT waste your time converting old GUI triggers, instead write them again in jass starting from zero.
It will be faster and easier.
Ok lets look at a simple GUI trigger:
Code:
HeroDies
Events
Unit - A unit Dies
Conditions
((Triggering unit) is A Hero) Equal to True
Actions
Hero - Instantly revive (Dying unit) at (Center of (Playable map area)), Show revival graphics
This trigger might be simple but it has all we need, it has an Event, an Action and a Condition.
Lets see how it looks when we convert it to text:
(Select the trigger and go to Edit->Convert to Custom Text)
JASS:
function Trig_HeroDies_Conditions takes nothing returns boolean
if ( not ( IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) == true ) ) then
return false
endif
return true
endfunction
function Trig_HeroDies_Actions takes nothing returns nothing
call ReviveHeroLoc( GetDyingUnit(), GetRectCenter(GetPlayableMapRect()), true )
endfunction
//===========================================================================
function InitTrig_HeroDies takes nothing returns nothing
set gg_trg_HeroDies = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_HeroDies, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition( gg_trg_HeroDies, Condition( function Trig_HeroDies_Conditions ) )
call TriggerAddAction( gg_trg_HeroDies, function Trig_HeroDies_Actions )
endfunction
It looks ugly doesn't it?
Well check this out: WE does not know how to generate vJASS, what you are actually looking at is old stupid jass.
So all you can do is convert GUI to jass, if you want vJASS you have to do it yourself.
//===========================================
The First thing we need to do is put a scope around that jass to make it vJASS:
JASS:
scope HeroDies // <---------<<
function Trig_HeroDies_Conditions takes nothing returns boolean
if ( not ( IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) == true ) ) then
return false
endif
return true
endfunction
function Trig_HeroDies_Actions takes nothing returns nothing
call ReviveHeroLoc( GetDyingUnit(), GetRectCenter(GetPlayableMapRect()), true )
endfunction
//===========================================================================
function InitTrig_HeroDies takes nothing returns nothing
set gg_trg_HeroDies = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_HeroDies, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition( gg_trg_HeroDies, Condition( function Trig_HeroDies_Conditions ) )
call TriggerAddAction( gg_trg_HeroDies, function Trig_HeroDies_Actions )
endfunction
endscope // <---------<<
Advice: Making scope name same as your trigger name will save you a lot of trouble when hunting for errors.
There is one problem here. vJASS cannot have spaces or underscores in scope names (jet). So you will have to rename your triggers from:
"Do Some Stuff" to "DoSomeStuff"
//===========================================
Lets see how stupid WE generates code:
It converted this:
Code:
((Triggering unit) is A Hero) Equal to True
to this:
JASS:
function Trig_HeroDies_Conditions takes nothing returns boolean
if ( not ( IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) == true ) ) then
return false
endif
return true
endfunction
But we will convert it to vJass now:
JASS:
private function Conditions takes nothing returns boolean
return IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) == true
endfunction
Who's my pretty boy
As you can see vJASS pwnz GUI generated jass.
//===========================================
Ok lets do the action now:
Code:
Hero - Instantly revive (Dying unit) at (Center of (Playable map area)), Show revival graphics
jass:
JASS:
function Trig_HeroDies_Actions takes nothing returns nothing
call ReviveHeroLoc( GetDyingUnit(), GetRectCenter(GetPlayableMapRect()), true )
endfunction
vJASS:
JASS:
private function Actions takes nothing returns nothing
call ReviveHero(GetDyingUnit(), 0, 0, true)
endfunction
Ok what happened now?
First of all we removed the whole GetRectCenter(GetPlayableMapRect()) thing.
We know that center of map is (0, 0) so instead of using ReviveHeroLoc we use ReviveHero function
{this also prevented location leak }
Ok but where did ReviveHero function come from?
How did I know what are it's arguments? Omg cohadar knows all jass functions :nuts:
Not even close.
What I know is how to use function list:
It is a cool feature in vJASS TESH editor,
you just type in few letters and it lists all functions that have that letters in name.
So it is even easier than finding functions inside GUI editor lists.
There is also a cool feature called autocompletion.
You type in a few first letters of a function inside a trigger: Rev
and a small pop-up window appears telling you what could be proper function names.
Damn this vJASS shit is easy.
But wait, it gets even better.
You type in the function name and a first bracket: ReviveHero(
and it pops up again showing you the arguments of the function.
Omg this vJASS shit is easier than GUI.
//========================================================
Lets get back to our trigger, we have one more thing to change, this:
JASS:
//===========================================================================
function InitTrig_HeroDies takes nothing returns nothing
set gg_trg_HeroDies = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_HeroDies, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition( gg_trg_HeroDies, Condition( function Trig_HeroDies_Conditions ) )
call TriggerAddAction( gg_trg_HeroDies, function Trig_HeroDies_Actions )
endfunction
Ok where did this come from, there was no such thing in GUI?
Actually there was, it is the event:
Code:
Unit - A unit Dies
Lets convert this to vJASS before we continue:
JASS:
//===========================================================================
private function Init takes nothing returns nothing
local trigger trig = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition( trig, Condition( function Conditions ) )
call TriggerAddAction( trig, function Actions )
endfunction
Create the trigger:
JASS:
local trigger trig = CreateTrigger()
Add event to the trigger:
JASS:
call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_DEATH )
Add condition to the trigger:
JASS:
call TriggerAddCondition( trig, Condition( function Conditions ) )
Add action to the trigger:
JASS:
call TriggerAddAction( trig, function Actions )
So basically what Init does here is connects unit dies event with our functions.
Very important: vJass does not automatically know what is triggers InitTrig function so you have to specify it after scope declaration.
JASS:
scope HeroDies initializer Init
// initializer function can have any name, I just personally prefer Init
This whole Init part might sound complicated but the fact is you don't have to learn it.
What you do is create a simple trigger with only an event:
For example spell effect:
Code:
StealLife
Events
Unit - A unit Starts the effect of an ability
Conditions
(Ability being cast) Equal to StealLife
Actions
Convert it to jass:
JASS:
function Trig_StealLife_Conditions takes nothing returns boolean
if ( not ( GetSpellAbilityId() == 039;A000039; ) ) then
return false
endif
return true
endfunction
function Trig_StealLife_Actions takes nothing returns nothing
endfunction
//===========================================================================
function InitTrig_StealLife takes nothing returns nothing
set gg_trg_StealLife = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_StealLife, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( gg_trg_StealLife, Condition( function Trig_StealLife_Conditions ) )
call TriggerAddAction( gg_trg_StealLife, function Trig_StealLife_Actions )
endfunction
and then to vJASS:
JASS:
scope StealLife initializer Init //<---<< don't forget to specify Init function
private function Conditions takes nothing returns boolean
return GetSpellAbilityId() == 039;A000039;
endfunction
private function Actions takes nothing returns nothing
// Add spell code here
endfunction
//===========================================================================
private function Init takes nothing returns nothing
local trigger trig = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( trig, Condition( function Conditions ) )
call TriggerAddAction( trig, function Actions )
endfunction
endscope
And than simply code the spell.
You do not have to remember how to do the whole TriggerAddCondition( trig, Condition( function Conditions ) ) stuff.
//======================================================
I attached a map with 2 simple triggers. Triggers are in GUI.
Your job is to convert them to vJASS as a practise.
All info you need to do that is in this tutorial,
and if you bump into any problems came here and tell us about it.
//======================================================
You might have noticed that a lot of things in this tutorial are not explained,
what is a scope, what is public, what is private?
why you change things the way you do?
This tutorial was meant to show you how to start coding vJASS the quickest way possible.
In order to learn why things are done they way the are,
and what do they mean you will have to learn yourself.
I do not believe that vJASS can be learned from tutorials,
you will simply have to code in vJASS every day and learn how and why to do things every day.
That is how you learned GUI didn't you?
//======================================================
TIP: There is a file jasshelper.html somewhere in NewGen directory, find it.
WARNING: When using NewGen always save map before you test it or it will not work.
ADVICE: Keep practising.