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

[vJASS] //! textmacro_once

Discussion in 'Triggers & Scripts' started by NEL, Dec 10, 2018.

  1. NEL

    NEL

    Joined:
    Mar 6, 2017
    Messages:
    112
    Resources:
    0
    Resources:
    0
    What is the main usage of
    //! textmacro_once
    ? and Why we need this?


    I have a few examples.


    Test A:
    Code (vJASS):
    //! textmacro_once Sample
        call BJDebugMsg("textmacro_once Sample")
    //! endtextmacro

    function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
        //! runtextmacro Sample()
        //! runtextmacro Sample()
        //! runtextmacro Sample()
    endfunction
    Result:
    Code (Text):
    textmacro_once Sample
    textmacro_once Sample
    textmacro_once Sample





    Test B:
    Code (vJASS):
    //! textmacro Sample
        call BJDebugMsg("textmacro Sample")
    //! endtextmacro

    function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
        //! runtextmacro Sample()
        //! runtextmacro Sample()
        //! runtextmacro Sample()
    endfunction
    Result:
    Code (Text):
    textmacro Sample
    textmacro Sample
    textmacro Sample







    Test C:
    Code (vJASS):
    //! textmacro Sample
        call BJDebugMsg("textmacro Sample")
    //! endtextmacro

    //! textmacro_once Sample
        call BJDebugMsg("textmacro_once Sample")
    //! endtextmacro

    function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
        //! runtextmacro Sample()
        //! runtextmacro Sample()
        //! runtextmacro Sample()
    endfunction
    Result:
    Code (Text):
    textmacro Sample
    textmacro Sample
    textmacro Sample





    Test D:
    Code (vJASS):
    //! textmacro_once Sample
        call BJDebugMsg("textmacro_once Sample")
    //! endtextmacro

    //! textmacro Sample
        call BJDebugMsg("textmacro Sample")
    //! endtextmacro

    function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
        //! runtextmacro Sample()
        //! runtextmacro Sample()
        //! runtextmacro Sample()
    endfunction
    Result:
    Syntax Error







    //! textmacro_once
    and
    //! textmacro
    are have a same result in Test A and Test B, but in Test C and Test D are different.
     
  2. PurgeandFire

    PurgeandFire

    Code Moderator

    Joined:
    Nov 11, 2006
    Messages:
    7,420
    Resources:
    18
    Icons:
    1
    Spells:
    4
    Tutorials:
    9
    JASS:
    4
    Resources:
    18
    iirc, it is just useful to prevent name collisions.

    Let's say you have two systems submitted to the hive, and they both have a textmacro named
    //! textmacro DoStuff
    , both of which do the exact same thing. If a user tries to import both of your systems into his map, they'll get a syntax error saying that there are two textmacros declared (the compiler doesn't know which one to choose). At this point, you could do any of these options:
    • Change the name of both textmacros accordingly (to something more specific)
    • Delete one of the textmacros
    • Make them both
      textmacro_once
    The third option will keep things working without having to change the name of your textmacros. Once it encounters the first textmacro_once named "DoStuff", it will ignore any other textmacro declarations that are named "DoStuff". So your code should work.

    Personally, I've never had to use that feature. I'd usually opt for option #1 (renaming the textmacros) or consolidating the textmacros into a separate trigger that both of the systems can feed off of.
     
  3. NEL

    NEL

    Joined:
    Mar 6, 2017
    Messages:
    112
    Resources:
    0
    Resources:
    0
    Thank you for your wonderful reply. I think, this post will be useful to other fellow map makers.
    +rep