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. Hey guys, we've posted the Results for the 30th Modeling Contest. Check them out!
    Dismiss Notice
  3. The 15th Mini-Mapping Contest came to an end. The Secrets of Warcraft 3 are soon to be revealed! Come and vote in the public poll for your favorite maps.
    Dismiss Notice
  4. The 12th incarnation of the Music Contest is LIVE! The theme is Synthwave. Knight Rider needs a song to listen to on his journey. You should definitely have some fun with this theme!
    Dismiss Notice
  5. 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
  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.

[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,427
    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