1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  4. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  5. Units have been turned into heroes in our latest Icon Contest! Vote for the best icon set at the Icon Contest #18 Poll!
    Dismiss Notice
  6. The poll for Hive's 12th Concept Art Contest is up! Go cast your vote for your favourite genie!
    Dismiss Notice
  7. The raddest synthwave tracks were chosen - Check out our Music Contest #12 - Results and congratulate the winners!
    Dismiss Notice
  8. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[JASS] Learning JASS. Last Question

Discussion in 'Triggers & Scripts' started by Starquizer, Jun 9, 2009.

  1. Starquizer

    Starquizer

    Joined:
    Mar 3, 2006
    Messages:
    1,526
    Resources:
    6
    Maps:
    1
    Spells:
    2
    Tutorials:
    3
    Resources:
    6
    Learning vJASS

    I have asked before how to learn JASS but this will be the last question to ask how to learn JASS.

    I am in a dire need of learning JASS but I'm not a programmer, how do I learn JASS. There is JASS manual but I can't learn from it or don't understand how to use it when making JASS. Please, good people of Hiveworkshop point me to where to start JASS and become profesional using it.
     
    Last edited: Aug 15, 2009
  2. Feroc1ty

    Feroc1ty

    Joined:
    Aug 9, 2008
    Messages:
    60
    Resources:
    0
    Resources:
    0
    Start off by converting GUI triggers into jass, getting rid of all the BJs, and replacing as many globals into locals as possible.

    Suggest you get Jass New Gen, it makes vJass very easy.
     
  3. raid1000

    raid1000

    Joined:
    May 1, 2008
    Messages:
    1,017
    Resources:
    0
    Resources:
    0
  4. Eleandor

    Eleandor

    Joined:
    Aug 21, 2005
    Messages:
    3,681
    Resources:
    2
    Models:
    1
    Tutorials:
    1
    Resources:
    2
    If you're talking about jasshelper manual, that's considered advanced jass. So don't let it be a surprise that if you're new to the programming scene, jasshelper manual won't learn you anything yet.

    Raid posted a good link to get you started.
     
  5. Ciebron

    Ciebron

    Joined:
    Apr 6, 2008
    Messages:
    760
    Resources:
    2
    Spells:
    2
    Resources:
    2
    no one can tell YOU how to learn jass. everyone have thier own way to learn
     
  6. Starquizer

    Starquizer

    Joined:
    Mar 3, 2006
    Messages:
    1,526
    Resources:
    6
    Maps:
    1
    Spells:
    2
    Tutorials:
    3
    Resources:
    6
    You mean making normal triggers as if I am using GUI, like kill unit, create unit ... etc then convert them to JASS. But how could I get rid of BJs if I don't know the function is a BJ or not ?
     
  7. Starquizer

    Starquizer

    Joined:
    Mar 3, 2006
    Messages:
    1,526
    Resources:
    6
    Maps:
    1
    Spells:
    2
    Tutorials:
    3
    Resources:
    6
    • Initialization
      • Events
        • Map initialization
      • Conditions
      • Actions


    When converted to JASS

    Code (vJASS):
    function Trig_Initialization_Actions takes nothing returns nothing
    endfunction
    //===========================================================================
    function InitTrig_Initialization takes nothing returns nothing
        set gg_trg_Initialization = CreateTrigger(  )
        call TriggerAddAction( gg_trg_Initialization, function Trig_Initialization_Actions )
    endfunction
     


    Is this a native or BJ ? And where is the event 'Map Initialization' in the JASS code ?
     
  8. Silvenon

    Silvenon

    Joined:
    Nov 22, 2006
    Messages:
    1,233
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    I suggest getting Jass NewGen Pack whether you'll use extended JASS (vJass) or not. You can find it on wc3c.net under Resources > Tools. It has syntax highlighting, so you won't need an additional JASS editor.

    But I suggest starting with vJass, because you don't have to know regular JASS to start vJass, afaik.

    All the BJs will be highlighted with the "evil red color" :p, so you'll notice. Once you've found a BJ, you'll know how to replace it if you move the type cursor to that function and then you can do ctrl + left click on that function. The function list will pop-up and you'll find your way.

    TriggerAddAction is a native, for example, but if you convert a generic unit event to JASS, you'll notice it has a BJ suffix (and it's highlighted with red). Most BJs have that suffix, but not all of them.

    I think he's talking about this one :D.
     
  9. Starquizer

    Starquizer

    Joined:
    Mar 3, 2006
    Messages:
    1,526
    Resources:
    6
    Maps:
    1
    Spells:
    2
    Tutorials:
    3
    Resources:
    6
    Yes I noticed this when I convert this trigger to JASS:

    • T2JASS
      • Events
        • Unit - A unit Dies
      • Conditions
      • Actions


    Code (vJASS):
    call TriggerRegisterAnyUnitEventBJ( gg_trg_T2JASS, EVENT_PLAYER_UNIT_DEATH )


    In order to make it native, it must be (I think):

    Code (vJASS):
    call TriggerAddEvent(gg_trg_T2JASS,EVENT)
    right ?
     
  10. Eleandor

    Eleandor

    Joined:
    Aug 21, 2005
    Messages:
    3,681
    Resources:
    2
    Models:
    1
    Tutorials:
    1
    Resources:
    2
    No.

    One of the exceptions where BJ's aren't that bad is event registrations. TriggerRegisterAnyUnitEventBJ has following native counterpart:

    TriggerRegisterPlayerUnitEvent. However, that event only works on units of a specified player. What TriggerRegisterAnyUnitEventBJ does is loop through all players and register the PlayerUnitEvent for the picked player.

    You're also unlucky to have chosen "Map Initialization" as your event, because there's no such event in jass. In jass, you have to check the checkbox at the top of the trigger that reads "map initialization".

    Triggers are also something "difficult" to work with if you're new to jass. Basically, a trigger is an object. Events are registered to triggers. Once registered they cannot be removed, hence why you don't add events (and don't remove events) but register them.
    Conditions and actions can be added and removed though. A big difference with a GUI trigger is that in jass you can add as many actions to a trigger as you want, while in GUI you can only add one action (which consists of all sub-actions you see in GUI).
     
  11. Starquizer

    Starquizer

    Joined:
    Mar 3, 2006
    Messages:
    1,526
    Resources:
    6
    Maps:
    1
    Spells:
    2
    Tutorials:
    3
    Resources:
    6
    So this is better than the native function:
    Code (vJASS):
    call TriggerRegisterPlayerEvent(TRIGGER,PLAYER,EVENT)



    So all the list of actions are considered as on action.
     
  12. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,542
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    JNGP is almost a vital tool to do JASS, as it really makes it easier. Better global control allows you to use globals for tasks easier. Library and scopes allow better naming of code. Finally the native list allows for easier finding of needed natives. Also the syntax checker is less fail than WE's normal one, and so will not crash if you do some kinds of errors and will do correct reports of invalid lines.
     
  13. Silvenon

    Silvenon

    Joined:
    Nov 22, 2006
    Messages:
    1,233
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    Yeah, but you have to understand why. TriggerRegisterPlayerEvent can only register one player per call, so what TriggerRegisterAnyUnitEventBJ is it registers the event for all players (through a loop).

    Yeah. People who work in GUI have a different concept of a trigger. They think that a trigger is something that in fact is some kind of a "folder" where you can have multiple triggers.

    For example:

    Code (vJASS):
    function Trig_Initialization_Actions takes nothing returns nothing
    endfunction
    //===========================================================================
    function InitTrig_Initialization takes nothing returns nothing
        set gg_trg_Initialization = CreateTrigger( )
        call TriggerAddAction( gg_trg_Initialization, function Trig_Initialization_Actions )
    endfunction


    Now I have only one trigger, but I can do this:

    Code (vJASS):
    function T_Actions takes nothing returns nothing
    endfunction

    function Trig_Initialization_Actions takes nothing returns nothing
    endfunction
    //===========================================================================
    function InitTrig_Initialization takes nothing returns nothing
        local trigger t = CreateTrigger()
        set gg_trg_Initialization = CreateTrigger( )
        call TriggerAddAction( gg_trg_Initialization, function Trig_Initialization_Actions )

        call TriggerRegisterPlayerUnitEvent(t, ...)
        call TriggerAddAction(t, function T_Actions)
    endfunction


    Now I have two triggers, each running independently on one another.
     
  14. Starquizer

    Starquizer

    Joined:
    Mar 3, 2006
    Messages:
    1,526
    Resources:
    6
    Maps:
    1
    Spells:
    2
    Tutorials:
    3
    Resources:
    6
    JNGP means Jass New Generation Pack.

    Ok, I tried it and found it a useful tool as it explain how BJs work with native.

    As Eleandor says about the register event:

    Code (vJASS):
    function TriggerRegisterAnyUnitEventBJ takes trigger trig, playerunitevent whichEvent returns nothing
        local integer index
        set index = 0
        loop
            call TriggerRegisterPlayerUnitEvent(trig, Player(index), whichEvent, null)
            set index = index + 1
            exitwhen index == bj_MAX_PLAYER_SLOTS
        endloop
    endfunction
     


    The BJ seems to check for every unit owned by player. But what if I used the native that is used in the BJ loop. What is the difference between them if I used them for a certain player and don't want to cycle through all players, which will be better to use BJ or native ?
     
    Last edited: Jun 9, 2009
  15. Silvenon

    Silvenon

    Joined:
    Nov 22, 2006
    Messages:
    1,233
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    I don't quite understand what you're saying...if you want to a single player event, use the native, if you want all the players, use the BJ.
     
  16. Starquizer

    Starquizer

    Joined:
    Mar 3, 2006
    Messages:
    1,526
    Resources:
    6
    Maps:
    1
    Spells:
    2
    Tutorials:
    3
    Resources:
    6
    Can I set a local variable to a pre-placed object ? also can I set globals to the same thing (pre-placed object) ?
     
  17. Reaper2008

    Reaper2008

    Joined:
    Jul 27, 2008
    Messages:
    1,117
    Resources:
    1
    Spells:
    1
    Resources:
    1
    TriggerRegisterAnyUnitEventBJ = any unit event (very useful, also better than 12 or so events to avoin one BJ
    TriggerRegisterPlayerUnitEvent = any unit belonging to player event.

    You need 12 TriggerRegisterPlayerUnitEvent to do what one TriggerRegisterAnyUnitEventBJ does, so its not inefficient in this case.
     
  18. Eleandor

    Eleandor

    Joined:
    Aug 21, 2005
    Messages:
    3,681
    Resources:
    2
    Models:
    1
    Tutorials:
    1
    Resources:
    2
    How is it better? It may make your code less obscure, but other than that there's no advantage by using the BJ.
     
  19. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,542
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    Starquizer, you can set a local to anything you wish as long as it is the same type as the local. Eg, you can set a unit local to anything that has a unit value, like CreateUnit, another variable, or even with a bug (which is unsafe) an integer represntation of a unit.

    The BJ for all players event creates about 16 events (12 for players and 4 for extra NPC players). Thus for efficency I advise only creating events for players who the event will have an affect. EG, if your map only uses players 1-4 and the neutrals, it is pointless making events for players 5-12, thus you can save 8 events and thus 8 handle indexes.

    This however is known as exessive efficency seeking. Generally it is advisable to do this when you have finished your map and are perfecting it.
     
  20. Starquizer

    Starquizer

    Joined:
    Mar 3, 2006
    Messages:
    1,526
    Resources:
    6
    Maps:
    1
    Spells:
    2
    Tutorials:
    3
    Resources:
    6
    Thanks for that help. But can i do this with globals and what is better globals or locals ? or in more precise question; when it is better to use local above global and use globals above of locals ?