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. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. 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. Raven0

    Raven0

    Joined:
    Oct 16, 2010
    Messages:
    878
    Resources:
    2
    Maps:
    2
    Resources:
    2
    I don't understand, can you give an example?

    HT? I'm assuming you meant a periodic timer. You can just use TimerStart(timer WhichTimer, real Duration, boolean Periodic, function Whichfunction). Which will call the specified function whenever the timer procs.
     
  2. mckill2009

    mckill2009

    Joined:
    Mar 10, 2009
    Messages:
    4,696
    Resources:
    34
    Maps:
    5
    Spells:
    27
    JASS:
    2
    Resources:
    34
    like this...


    • Timer
      • Events
        • Unit - A unit Starts the effect of an ability
      • Conditions
        • (Ability being cast) Equal to Flame Strike
      • Actions
        • Hashtable - Save 13.00 as 1 of (Key (Triggering unit)) in Hash
        • Unit Group - Add (Triggering unit) to UGrp
        • Trigger - Turn on Timer Loop <gen>


    • Timer Loop
      • Events
        • Time - Every 1.00 seconds of game time
      • Conditions
      • Actions
        • Unit Group - Pick every unit in UGrp and do (Actions)
          • Loop - Actions
            • Set Timer = (Load 1 of (Key (Picked unit)) from Hash)
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • (Load 1 of (Key (Picked unit)) from Hash) Greater than 0.00
              • Then - Actions
                • Hashtable - Save (Timer - 1.00) as 1 of (Key (Picked unit)) in Hash
                • Set Timer = (Load 1 of (Key (Picked unit)) from Hash)
                • Floating Text - Create floating text that reads (String(Timer)) above (Picked unit) with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
                • Floating Text - Change (Last created floating text): Disable permanence
                • Floating Text - Set the velocity of (Last created floating text) to 100.00 towards 90.00 degrees
                • Floating Text - Change the lifespan of (Last created floating text) to 2.00 seconds
              • Else - Actions
                • Unit Group - Remove (Picked unit) from UGrp
                • Hashtable - Clear all child hashtables of child (Key (Picked unit)) in Hash
                • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                  • If - Conditions
                    • (UGrp is empty) Equal to True
                  • Then - Actions
                    • Game - Display to (All players) the text: TRIG OFF
                    • Trigger - Turn off (This trigger)
                  • Else - Actions


    Pls dont make the trigger in JASS, I just want to know how you save/load, what do I use as 'ID' (triggering unit, picked or just integer?)...

    yeah that's what I meant, thanks!...
     
  3. chobibo

    chobibo

    Joined:
    Sep 24, 2005
    Messages:
    2,701
    Resources:
    0
    Resources:
    0
    1. Depends on what your trying to store. If you want to attach data to a timer, then you would use the timer's handle id, if you want to attach data to a unit the the unit's handle id.
    2. Yes
     
  4. Fingolfin

    Fingolfin

    Joined:
    Jan 11, 2009
    Messages:
    3,195
    Resources:
    153
    Models:
    143
    Icons:
    1
    Packs:
    4
    Skins:
    2
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    153
    If you want to store several types of information to a single timer, you might be better off making a struct and store the struct handle to the timer.

    Example:

    Code (vJASS):

    struct myStruct
        real x
        real y
        unit u
    endstruct

    //and then make theese functions:

    function myCallback takes nothing returns nothing
    local myStruct S = LoadInteger(myHash, 0, GetHandleId(GetExpiredTimer()))
    //now you can retain your variables through the struct, i.e. "S.u" to get the stored unit!

    //Remember to type the following lines once you're done witn the struct, or the struct will not be recycled.
    call S.destroy()
    call RemoveSavedInteger(myHash, 0, GetHandleId(GetExpiredTimer()))
    endfunction

    function AttachStructToTimer takes unit u, real x, real y returns nothing
    local timer t = CreateTimer()
    local myStruct S = myStruct.create()
    set S.u = u
    set S.x = x
    set S.y = y
    call SaveInteger(MyHash, 0, GetHandleId(t), S) //This attaches our struct "S" to the timer.
    call TimerStart(t, false, false, function myCallback)
    endfunction
     


    I am just writing out of my head now so this might not compile, but i hope you get the point. Structs are excellent for storing bundles of information like this.
     
  5. baassee

    baassee

    Joined:
    Nov 14, 2008
    Messages:
    3,220
    Resources:
    17
    Spells:
    14
    Tutorials:
    3
    Resources:
    17
    Usually you don't use hashtables for making spells in vJASS, we got structs.

    In plain JASS it's better to use a timer's handle id to attach your data instead of the caster's id thus it will always be a unique id every single time which will never clash with anyother spell instance (as they won't use that timer). That's the easiest way in JASS what I know of. If you remember the pounce spell I made, it uses this technique pretty well.
     
  6. Garfield1337

    Garfield1337

    Joined:
    Jul 6, 2009
    Messages:
    1,806
    Resources:
    4
    Maps:
    1
    Spells:
    3
    Resources:
    4
    ...which makes a spell SUMI.
    If you had attached data to caster's id,it would be MUI but not SUMI. Just saying the term SUMI isn't useless.
     
  7. baassee

    baassee

    Joined:
    Nov 14, 2008
    Messages:
    3,220
    Resources:
    17
    Spells:
    14
    Tutorials:
    3
    Resources:
    17
    I say it is useless as MUI back in the old days should be "SUMI" in the present days. It's just that the rules are very unclear about this.
     
  8. mckill2009

    mckill2009

    Joined:
    Mar 10, 2009
    Messages:
    4,696
    Resources:
    34
    Maps:
    5
    Spells:
    27
    JASS:
    2
    Resources:
    34
    Now this is the answer I'm looking forward to know...It enlightens me up
    because I've seen scripts with timer as ID, so Im confirming if that's the best way...

    @Fingolfin

    From the looks of it, it's much easier than hashtables...lol!
     
  9. Garfield1337

    Garfield1337

    Joined:
    Jul 6, 2009
    Messages:
    1,806
    Resources:
    4
    Maps:
    1
    Spells:
    3
    Resources:
    4
    I hope you don't mind if i ask few questions too,mckill :eek:

    What's the ExecuteFunc() native for? Why not just use call [function name]? According to Jasshelper manual,the ExecuteFunc() is used to initialize libraries; can it be done by calling the initializer too?

    And another thing is,are functions from scope added to map header like functions from libraries so they can be used elsewhere?
     
  10. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,596
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    ExecuteFunc() takes a string representing the name of the function to execute. This means you can use it to run variable code (pass it a variable of type string).

    Calls on the otherhand compile to call instructions, and as such can not take a variable as a target as they reference a specific point in the code.

    ExecuteFunc() has other useful properties.
    1. I believe it starts a new thread (new stack) and thus can avoid oplimit.
    2. Can run functions below the call to this function (unlike real calls which are limited to above only).
    3. Can be used to provide variable function flow control.


    Scopes in Vjass are placed in the script in the order you place them in the trigger editor, thus libaries are for global functions and scopes for map specific functions. A spell should be in a scope but all its used (recyclable) components in a library.
     
  11. mckill2009

    mckill2009

    Joined:
    Mar 10, 2009
    Messages:
    4,696
    Resources:
    34
    Maps:
    5
    Spells:
    27
    JASS:
    2
    Resources:
    34
    I'm not reading Jass manual yet but I think ExecuteFunc() can call funtions 'immediately' even with waits...

    I dont dont think you can use it elsewhere coz scopes are blockers...well
    of course I maybe wrong...

    *Pls dont be offended but I think you're asking the wrong guy here, Im still learning :)...
     
  12. baassee

    baassee

    Joined:
    Nov 14, 2008
    Messages:
    3,220
    Resources:
    17
    Spells:
    14
    Tutorials:
    3
    Resources:
    17
    Avoid using ExecuteFunc(), try to use TriggerEvaluate(a boolexprtrigger) instead (just pass the function thru a Condition(function) call ) because Vex's optimizer breaks it. It doesn't break TriggerEvaluate though.

    I think the functions in a scope are unreliable as the scopes are compiled together and having one scope calling another will probably bug the compiling. That's what the "require" keyword within libraries are for, putting the library in top of the other so it will be 100% safe to use that function and no syntax errors.
     
    Last edited: Mar 11, 2011
  13. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,596
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    This is the function he referd to (Correct).
    This is what he asks (WRONG).

    baassee, please do more research or atleast some checking up before posting as mistakes like that really confuse people.

    You need to attach a boolexpr to a trigger and pass the TriggerEvaluate function the trigger inorder to run code with it.
     
  14. baassee

    baassee

    Joined:
    Nov 14, 2008
    Messages:
    3,220
    Resources:
    17
    Spells:
    14
    Tutorials:
    3
    Resources:
    17
    My bad, confused it with TriggerAddCondition native.
     
  15. mckill2009

    mckill2009

    Joined:
    Mar 10, 2009
    Messages:
    4,696
    Resources:
    34
    Maps:
    5
    Spells:
    27
    JASS:
    2
    Resources:
    34
    Are these the same?, and which is better?...does it leak?...
    Also, do we have to use "\\"???...

    Code (vJASS):

    function sfxtest takes nothing returns nothing
      local unit u = GetTriggerUnit()
      local effect e
      set e = AddSpecialEffect("Abilities\\Spells\\Items\\TomeOfRetraining\\TomeOfRetrainingCaster.mdl", GetUnitX(u), GetUnitY(u))
      call DestroyEffect(e)
      set u = null
      set e = null
    endfunction
    //===========================================================================
    function InitTrig_sfx takes nothing returns nothing
        local trigger t = CreateTrigger(  )
        call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_DEATH )
        call TriggerAddAction( t, function sfxtest )
        set t = null
    endfunction
     


    OR...

    Code (vJASS):

    function sfxtest takes nothing returns nothing
      local unit u = GetTriggerUnit()
      call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Items\\TomeOfRetraining\\TomeOfRetrainingCaster.mdl", GetUnitX(u), GetUnitY(u)))
      set u = null
    endfunction
    //===========================================================================
    function InitTrig_sfx takes nothing returns nothing
        local trigger t = CreateTrigger(  )
        call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_DEATH )
        call TriggerAddAction( t, function sfxtest )
        set t = null
    endfunction
     
     
  16. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,426
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    Second one is better. And yes, you have to use double back-slashes. "\" denotes an escape sequence. See string literals for more information.

    They both will do the same thing, but the first involves the unnecessary local declaration.
     
  17. mckill2009

    mckill2009

    Joined:
    Mar 10, 2009
    Messages:
    4,696
    Resources:
    34
    Maps:
    5
    Spells:
    27
    JASS:
    2
    Resources:
    34
    thank you, now my other question, when we code in JASS, usually we have this...

    AddSpecialEffect(string model name, real x, realy)

    so does anyone have a clue on where we can find the pattern for coding it, I mean for example, real x, how do you know that it's GetUnitX(blahhh)...I mean the FORMAT on how to do it?...

    ex...widgets???...
     
  18. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,426
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    You mean the native list? You can either use JassCraft/vim/jEdit or something similar, or you can just use the TESH that is built in with JNGP. Also, if you need to know what to use, you can always make a trigger and add some GUI code and convert it to custom text. Then you just look up the BJ in any of those programs and it will show you what to do to inline it.
     
  19. mckill2009

    mckill2009

    Joined:
    Mar 10, 2009
    Messages:
    4,696
    Resources:
    34
    Maps:
    5
    Spells:
    27
    JASS:
    2
    Resources:
    34
    No, I mean the FORMAT of coding like...

    1. effecttype t in AdSpellEffect
    2. You must put this one \\ instead of this one \
    3. You must do like this "I2S (i)", NOT this "I2S ("i")

    And alike...

    And there are something called widget(or something like that), what are those?...

    hmm...vim/JEdit?, I didnt know that...

    EDIT:

    Nvm, I got it...

    thanks Purge!
     
  20. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,426
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    Widgets are anything with life. (destructables, items, and units) :)