• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[vJASS] //! textmacro_once

Status
Not open for further replies.

NEL

NEL

Level 6
Joined
Mar 6, 2017
Messages
113
What is the main usage of //! textmacro_once? and Why we need this?


I have a few examples.


Test A:
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:
textmacro_once Sample
textmacro_once Sample
textmacro_once Sample





Test B:
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:
textmacro Sample
textmacro Sample
textmacro Sample







Test C:
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:
textmacro Sample
textmacro Sample
textmacro Sample





Test D:
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.
 
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.
 
  • Like
Reactions: NEL

NEL

NEL

Level 6
Joined
Mar 6, 2017
Messages
113
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.

Thank you for your wonderful reply. I think, this post will be useful to other fellow map makers.
+rep
 
Status
Not open for further replies.
Top