• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Need help understanding JASS triggers (A GUI trigger conversion)

Status
Not open for further replies.
Level 5
Joined
Feb 13, 2019
Messages
128
So you can convert GUI triggers to JASS, but I want to say I read somewhere the way they are written are inefficient and leak?

I may be misremembering but I guess my main question is this the standard way to go about triggering in JASS
  • Trigger Test
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Triggering unit) is A Hero) Equal to True
    • Actions
      • Game - Display to (All players) the text: ripirino
JASS:
function Trig_JASS_Test_Conditions takes nothing returns boolean
    if ( not ( IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) == true ) ) then
        return false
    endif
    return true
endfunction
function Trig_JASS_Test_Actions takes nothing returns nothing
    call DisplayTextToForce( GetPlayersAll(), "ripirino" )
endfunction
//===========================================================================
function InitTrig_JASS_Test takes nothing returns nothing
    set gg_trg_JASS_Test = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_JASS_Test, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_JASS_Test, Condition( function Trig_JASS_Test_Conditions ) )
    call TriggerAddAction( gg_trg_JASS_Test, function Trig_JASS_Test_Actions )
endfunction

Could/Should I just start using JASS for my triggers and typing them, what's a good way to word this, ummm, in this format? I mean I think so right? they're just functions going off? The trigger is being created and named via function InitTrig_JASS_Test takes nothing returns nothing set gg_trg_JASS_Test = CreateTrigger( ), ? (Am I setting some type of variable? Set = is generally for setting variables I thought? )

this is where I get a bit confused, call TriggerRegisterAnyUnitEventBJ( gg_trg_JASS_Test, EVENT_PLAYER_UNIT_DEATH ) so it's "calling" a native(?) command in JASS that is when any unit dies, but what is a call? it you could say it's saying "hey do this?" and it looks for any unit to die? is it just always running? Why don't I need like an event checking every second to see if something died?

and these are also "called",? and told to use the actions as well via
call TriggerAddAction( gg_trg_JASS_Test, function Trig_JASS_Test_Actions )
endfunction
and it's actions (the function called?) is up top as

JASS:
 function Trig_JASS_Test_Conditions takes nothing returns boolean
    if ( not ( IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) == true ) ) then
        return false
    endif
    return true
endfunction
function Trig_JASS_Test_Actions takes nothing returns nothing
    call DisplayTextToForce( GetPlayersAll(), "ripirino" )
endfunction

Which says hey, if this, then do this?

JASS:
function Trig_XXXXXX_Actions takes nothing returns nothing
endfunction

//===========================================================================
function InitTrig_XXXXXX  takes nothing returns nothing
    set gg_trg_XXXXXX = CreateTrigger(  )
    call TriggerAddAction( gg_trg_XXXXXX, function Trig_XXXXXX_Actions )
endfunction


Sorry if this is a dumb question, I'm reading JASS tutorials as well, I just feel as if I learn better bouncing ideas off someone, and asking dumb questions, and just going in and learning by doing.


Should I write every trigger in JASS? Is GUI a lost cause or is it best to use both?

Could I start writing triggers or trigger like events in JASS like this?
 
Level 5
Joined
Feb 13, 2019
Messages
128
Sorry if this is poorly worded, it's 3am where I am located, and my spacebar actually just broke, so tomorrow when I get a keyboard I can make this more clear lol!
 
Functions can be catogerized in:
  1. There are native JASS functions that access to internal blizzard code (we don't see what they do), the natives. common.j -- patch 1.30.4 | HIVE
  2. There are provided help functions by blizzard, which take usage of the natives + possibly include own logics, the BlizzardJass (BJs), blizzard.j -- patch 1.30.4 | HIVE.
  3. One can write own functions, which can or call natives, BJs, + include own logics ( loops, ifs, .. )
One can run all functions by using call keyword and then providing parameters. ( values and types a function expects when being called )
Function names in GUI are automatically created in background, like "Trig_XXXXXX_Actions", to show it is a trigger action function. But you may use any other (most) words too, that are no special JASS keywords.

So the final code could look like this:

JASS:
//name changed
function CheckUnitType takes nothing returns boolean
    if ( IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) == true ) then
        return true
    endif
    return false
endfunction

// name changed
function DisplayTextOnDeath takes nothing returns nothing
    call DisplayTextToForce( GetPlayersAll(), "ripirino" )
endfunction

function InitTrig_JASS_Test takes nothing returns nothing
    set gg_trg_JASS_Test = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_JASS_Test, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_JASS_Test, Condition( function CheckUnitType ) ) // was adapted
    call TriggerAddAction( gg_trg_JASS_Test, function DisplayTextOnDeath ) // was adapted
endfunction

What can be done now is shorten code. I shorten the condition a lot, and have a look how a local trigger variable is used now at the bottom function.

JASS:
// IsUnitType is a function returning a boolean
// which means we can directly return its returned value and it'll be true/false
function CheckUnitType takes nothing returns boolean
    return IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO)
endfunction

function DisplayTextOnDeath takes nothing returns nothing
    call DisplayTextToForce( GetPlayersAll(), "ripirino" )
endfunction

function InitTrig_JASS_Test takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition(t, Condition( function CheckUnitType ) )
    call TriggerAddAction(t, function DisplayTextOnDeath )
endfunction
One could do more, like for example to lookup what the BJs do in background and if it's really needed to call it, but I guess it's a good start.

Should I write every trigger in JASS? Is GUI a lost cause or is it best to use both?
GUI is not bad per se. The problem with GUI is that it often can become weird because one does not always know and see what is going on in background.
I think it's for sure good if you also learn JASS, to know how things work, and that you really can use it. And from then, you might use GUI more precise, because you know how it looks like.

I recommend reading JASS Class. Not necessarily making the class itself, but many tutorials are lined there, too, which might help.
You're also right about just asking from time to time, it makes perfect sense. The help forum is pretty good here, and is welcoming interested newcomers. :)
 
Last edited:
Level 5
Joined
Feb 13, 2019
Messages
128
Functions can be catogerized in:
  1. There are native JASS functions that access to internal blizzard code (we don't see what they do), the natives. common.j -- patch 1.30.4 | HIVE
  2. There are provided help functions by blizzard, which take usage of the natives + possibly include own logics, the BlizzardJass (BJs), blizzard.j -- patch 1.30.4 | HIVE.
  3. One can write own functions, which can or call natives, BJs, + include own logics ( loops, ifs, .. )
One can run all functions by using call keyword and then providing parameters. ( values and types a function expects when being called )
Function names in GUI are automatically created in background, like "Trig_XXXXXX_Actions", to show it is a trigger action function. But you may use any other (most) words too, that are no special JASS keywords.

So the final code could look like this:

JASS:
//name changed
function CheckUnitType takes nothing returns boolean
    if ( IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) == true ) then
        return true
    endif
    return false
endfunction

// name changed
function DisplayTextOnDeath takes nothing returns nothing
    call DisplayTextToForce( GetPlayersAll(), "ripirino" )
endfunction

function InitTrig_JASS_Test takes nothing returns nothing
    set gg_trg_JASS_Test = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_JASS_Test, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_JASS_Test, Condition( function CheckUnitType ) ) // was adapted
    call TriggerAddAction( gg_trg_JASS_Test, function DisplayTextOnDeath ) // was adapted
endfunction

What can be done now is shorten code. I shorten the condition a lot, and have a look how a local trigger variable is used now at the bottom function.

JASS:
// IsUnitType is a function returning a boolean
// which means we can directly return its returned value and it'll be true/false
function CheckUnitType takes nothing returns boolean
    return IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO)
endfunction

function DisplayTextOnDeath takes nothing returns nothing
    call DisplayTextToForce( GetPlayersAll(), "ripirino" )
endfunction

function InitTrig_JASS_Test takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition(t, Condition( function CheckUnitType ) )
    call TriggerAddAction(t, function DisplayTextOnDeath )
endfunction
One could do more, like for example to lookup what the BJs do in background and if it's really needed to call it, but I guess it's a good start.


GUI is not bad per se. The problem with GUI is that it often can become weird because one does not always know and see what is going on in background.
I think it's for sure good if you also learn JASS, to know how things work, and that you really can use it. And from then, you might use GUI more precise, because you know how it looks like.

I recommend reading JASS Class. Not necessarily making the class itself, but many tutorials are lined there, too, which might help.
You're also right about just asking from time to time, it makes perfect sense. The help forum is pretty good here, and is welcoming interested newcomers. :)


Thank you so much, I really appreciate you taking the time for all that, and I'll definitely get into checking out the JASS class and everything ASAP but the space-bar on my laptop broke so I have to get a keyboard first lol.
 
Level 9
Joined
Jul 30, 2018
Messages
445
Sorry if this is a but off-topic, and sorry for jumping in your thread, but I have been thinking about getting into JASS too, but are there some developer tools for JASS? It just seems awfully tedious to write to the trigger editor without any kind of syntax correcting, list of available commands and auto-finish. I've tried some programs like JassCraft, but it says it can't find the Warcraft 3 MPQ files and doesn't work..
 
JNGP, then WEX editor could be used, which have TESH, the highlithing and so directly implemented.
There's now no game MPQ anymore but CASC, that's one reason why older tools, like mentioned editors don't work anymore.

If you want to use VS Code you could try out vjass support extension for Visual Studio Code. But code needs to be ported, compiled and so in the map itself.

Many coders also simply use something like Notepad, maybe even with JASS plugin for highliting plugin and then they also port it into the map. (you can google for such plugin pretty easy) One then needs to have common.j and blizzard.j opened (lins in post above), and look for exact functon names. But without practice this is may be a tedious way, and even with practice it's not really best. Because fast syntax checking and so is lacking.

I expected it coming in default editor, too but somehow it took already so long. I hope it will be part of next patch release.
 
Status
Not open for further replies.
Top