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. We have recently started the 16th edition of the Mini Mapping Contest. The theme is mini RPG. Do check it out and have fun.
    Dismiss Notice
  4. Dismiss Notice
  5. The Highway to Hell has been laid open. Come along and participate in the 5th Special Effect Contest.
    Dismiss Notice
  6. 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] Natives and Local variables ...

Discussion in 'Triggers & Scripts' started by mckill2009, Feb 26, 2011.

  1. baassee

    baassee

    Joined:
    Nov 14, 2008
    Messages:
    3,220
    Resources:
    17
    Spells:
    14
    Tutorials:
    3
    Resources:
    17
    Right, this applies to JASS as no one does it in GUI ;)

    @mckill

    Useless BJ
    set udg_FCB_Level = GetUnitAbilityLevelSwapped('A02M', udg_FCB_Unit)


    Change it to GetUnitAbilityLevel(udg_FCB_Unit, 'A02M')

    • Custom script: set udg_FCB_Dummy = GetLastCreatedUnit()


    Useless to do in customscript as it does just like that in GUI.

    Why you try to change your BJs and you still keep some?
    • Hashtable - Save Handle OfFCB_Pt[1] as (Key fcbloc) of FCB_ID in Hash_01


    • Custom script: call EnableTrigger(gg_trg_Fallen_Corpse_Bombardment_Loop)


    Same as GUI, use GUI.

    • Custom script: set udg_FCB_Dummy = GetEnumUnit()


    Also same as GUI "Picked Unit"

    Sorry to say this but don't use points that are arrayed unless you're going to use 100 of them "temporarly". Make 2 variables instead as arrayed takes much more space.

    • Custom script: set udg_FCB_CorpseFalling = GetLastCreatedUnit()


    Converted GUI BJ, either use the GUI or make it real JASS.

    • Set FCB_Pt[1] = (Load (Key fcbloc) of FCB_ID in Hash_01)


    Leaks as you don't remove it in the then part. You stilled saved it in the hash, don't worry.

    • Custom script: call ExplodeUnitBJ(udg_FCB_Dummy)


    Use the GUI if you cannot remove the BJ proper. Read about what's behind the BJs.

    • Custom script: call UnitApplyTimedLifeBJ( 0.01, 'BTLF', udg_FCB_Dummy )


    Useless as you remove the unit instantly afterwards before the 0.01 timer hasn't even started.

    Stop create spells in GUI, convert the whole trigger instead and start from there. Much more fun than judging GUI code.
     
  2. mckill2009

    mckill2009

    Joined:
    Mar 10, 2009
    Messages:
    4,696
    Resources:
    34
    Maps:
    5
    Spells:
    27
    JASS:
    2
    Resources:
    34
    Aha!, no wonder why "GetUnitAbilityLevel" did not work coz I used "GetUnitAbilityLevel('A02M', udg_FCB_Unit)...

    Roger!

    The reason why Im doin all this in custom script so that I can familiarize
    the codes of saving & loading in hash without the help of JNGP (next time I will)...

    Now I know a little like SaveUnitHandle, SaveInteger, etc... and how to
    load them...

    As I go step by step in doing this, I wil soon realize the importance of making it in REAL JASS...thanks to you guys!
     
  3. baassee

    baassee

    Joined:
    Nov 14, 2008
    Messages:
    3,220
    Resources:
    17
    Spells:
    14
    Tutorials:
    3
    Resources:
    17
    If you don't want to use JNGP, use JASSCraft. I think JC got this TESH like function too. Still only JASS.
     
  4. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,079
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Still better than World Editor JASS scripting, the one that has no initialization precedence, un-declarable global types and an accidental Ctrl + Z that can erase a day's work.
     
  5. baassee

    baassee

    Joined:
    Nov 14, 2008
    Messages:
    3,220
    Resources:
    17
    Spells:
    14
    Tutorials:
    3
    Resources:
    17
    Hehe this awakes some awful memories.
     
  6. mckill2009

    mckill2009

    Joined:
    Mar 10, 2009
    Messages:
    4,696
    Resources:
    34
    Maps:
    5
    Spells:
    27
    JASS:
    2
    Resources:
    34
    Another practice...Im studing coordinates...is this true JASS?...

    Code (vJASS):

    function WodSpell takes nothing returns boolean
        return (GetSpellAbilityId()=='A002')
    endfunction
     
    function WodAct takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local real x1 = GetUnitX(u)
        local real y1 = GetUnitY(u)
        local real x2 = GetSpellTargetX()
        local real y2 = GetSpellTargetY()    
        local unit o = CreateUnit (GetOwningPlayer(u), 'hfoo', x1,y1, 0)
        call IssuePointOrder(o, "move", x2, y2)
        set u = null
        set o = null    
    endfunction
     
    //===========================================================================
     
    function InitTrig_Wind_of_Decay takes nothing returns nothing
        local trigger t = CreateTrigger(  )
        call TriggerRegisterAnyUnitEventBJ      (t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddCondition                (t, Condition(function WodSpell))
        call TriggerAddAction                   (t, function WodAct )
        set t = null
    endfunction
     
     
  7. baassee

    baassee

    Joined:
    Nov 14, 2008
    Messages:
    3,220
    Resources:
    17
    Spells:
    14
    Tutorials:
    3
    Resources:
    17
    In JASS, you don't use any actions (you better learn this right away). You merge them with the conditions so instead of your trigger it will be like this:

    Code (vJASS):
    function WodSpell takes nothing returns boolean
        local unit u
        local unit o
        if GetSpellAbilityId()=='A002' then
            set u = GetTriggerUnit()
            set o = CreateUnit(GetTriggerPlayer(), 'hfoo', GetUnitX(u), GetUnitY(u), 0.)
            call IssuePointOrder(o, "move", GetSpellTargetX(), GetSpellTargetY())
            set u = null
            set o = null
        endif
        return false
    endfunction

    //===========================================================================
     
    function InitTrig_Wind_of_Decay takes nothing returns nothing
        local trigger t = CreateTrigger(  )
        call TriggerRegisterAnyUnitEventBJ      (t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddCondition                (t, Condition(function WodSpell))
        set t = null
    endfunction
     
  8. chobibo

    chobibo

    Joined:
    Sep 24, 2005
    Messages:
    2,702
    Resources:
    0
    Resources:
    0
    In the end, everything is compiled to jass, even the doodad placing; what you should ask for is if your script is optimized. I meant no offense, just clarifying.

    Now back on topic: that's a good start, using reals instead of location handles are better because they don't need allocation.

    <EDIT>
    Yeah baassee is right, triggercondition's execute faster because they don't support TriggerSleeps a.k.a Wait actions. It's like a one shot thread that the engine won't ever return to, think local variables. Also, it's not too bright to use waits when you're already scripting directly lol. I remembered one time... XD
     
  9. Fingolfin

    Fingolfin

    Joined:
    Jan 11, 2009
    Messages:
    3,205
    Resources:
    153
    Models:
    143
    Icons:
    1
    Packs:
    4
    Skins:
    2
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    153
    @Baassee: Shouldn't you null the variables outside of the if statement instead? Or do you only have to do that once you have given them a value?
     
  10. chobibo

    chobibo

    Joined:
    Sep 24, 2005
    Messages:
    2,702
    Resources:
    0
    Resources:
    0
    You don't need to null them if you don't initialize or use them.
     
  11. baassee

    baassee

    Joined:
    Nov 14, 2008
    Messages:
    3,220
    Resources:
    17
    Spells:
    14
    Tutorials:
    3
    Resources:
    17
    They are only declared, no values are assigned to them.
     
  12. mckill2009

    mckill2009

    Joined:
    Mar 10, 2009
    Messages:
    4,696
    Resources:
    34
    Maps:
    5
    Spells:
    27
    JASS:
    2
    Resources:
    34
    @baassee, chobibo

    makes perfect sense...yeah Im gonna use reals for now coz one expert said that
    it does not interrupt orders...

    but wait...the return false is 'else'?...
     
  13. baassee

    baassee

    Joined:
    Nov 14, 2008
    Messages:
    3,220
    Resources:
    17
    Spells:
    14
    Tutorials:
    3
    Resources:
    17
    SetUnitX/Y doesn't interrupt orders. SetUnitPosition does. Both are using coordinates.

    It's the trigger condition. It has to return a boolean value and because we're not using any actions, it should return false always no matter what as it would else fire the actions when there are any. There are no else part in the if statement.
     
  14. chobibo

    chobibo

    Joined:
    Sep 24, 2005
    Messages:
    2,702
    Resources:
    0
    Resources:
    0
    what interrupts orders?
     
  15. baassee

    baassee

    Joined:
    Nov 14, 2008
    Messages:
    3,220
    Resources:
    17
    Spells:
    14
    Tutorials:
    3
    Resources:
    17
    SetUnitPosition.
     
  16. chobibo

    chobibo

    Joined:
    Sep 24, 2005
    Messages:
    2,702
    Resources:
    0
    Resources:
    0
    Ah, I thought he was referring to locations.
     
  17. baassee

    baassee

    Joined:
    Nov 14, 2008
    Messages:
    3,220
    Resources:
    17
    Spells:
    14
    Tutorials:
    3
    Resources:
    17
    Isn't there a SetUnitPositionLoc too?
     
  18. chobibo

    chobibo

    Joined:
    Sep 24, 2005
    Messages:
    2,702
    Resources:
    0
    Resources:
    0
    Yes, but what I meant was, I thought he was referring to locations interrupting orders.
     
  19. baassee

    baassee

    Joined:
    Nov 14, 2008
    Messages:
    3,220
    Resources:
    17
    Spells:
    14
    Tutorials:
    3
    Resources:
    17
    No I think he meant the GUI "Move Unit Instantly" which is SetUnitPosition.
     
  20. mckill2009

    mckill2009

    Joined:
    Mar 10, 2009
    Messages:
    4,696
    Resources:
    34
    Maps:
    5
    Spells:
    27
    JASS:
    2
    Resources:
    34
    yeah Im reffering to SetUnitX/Y, but is IssuePointOrder doesnt interrupt order also?...