1. The contestants were to create water structures for the 20th Terraining Contest. Choose one in the public poll!
    Dismiss Notice
  2. Join other hivers in a friendly concept-art contest. The contestants have to create a genie coming out of its container. We wish you the best of luck!
    Dismiss Notice
  3. The Melee Mapping Contest #4: 2v2 - Results are out! Step by to congratulate the winners!
    Dismiss Notice
  4. We're hosting the 15th Mini-Mapping Contest with YouTuber Abelhawk! The contestants are to create a custom map that uses the hidden content within Warcraft 3 or is inspired by any of the many secrets within the game.
    Dismiss Notice
  5. Check out the Staff job openings thread.
    Dismiss Notice

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

Discussion in 'Triggers & Scripts' started by blanabasjim, Apr 26, 2019.

  1. blanabasjim

    blanabasjim

    Joined:
    Feb 13, 2019
    Messages:
    80
    Resources:
    0
    Resources:
    0
    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


    Code (vJASS):
    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

    Code (vJASS):
     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?

    Code (vJASS):

    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?
     
  2. blanabasjim

    blanabasjim

    Joined:
    Feb 13, 2019
    Messages:
    80
    Resources:
    0
    Resources:
    0
    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!
     
  3. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,107
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    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:

    Code (vJASS):

    //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.

    Code (vJASS):

    // 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. :)
     
    Last edited: Apr 28, 2019
  4. blanabasjim

    blanabasjim

    Joined:
    Feb 13, 2019
    Messages:
    80
    Resources:
    0
    Resources:
    0

    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.
     
  5. Sabe

    Sabe

    Joined:
    Jul 30, 2018
    Messages:
    223
    Resources:
    1
    Spells:
    1
    Resources:
    1
    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..
     
  6. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,107
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    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.
     
  7. Pyrogasm

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    2,436
    Resources:
    0
    Resources:
    0
    JASS in Notepad++, doesn't include any new Blz natives AFAIK. In 1.31 maps can be built as project and I believe the PTR notes said it will eventually allow code in external files. I could have imagined that, though.