Text Macros

Naga'sShadow

Ultra Cool Member
Reaction score
49
I've looked but not seen anything about them outside of systems, how exactly to they work, and is there a tutorial out there about them?
 

saw792

Is known to say things. That is all.
Reaction score
280
The best 'tutorial' about them would be the JassHelper manual.

Textmacros are used to replace code that would be called frequently with minor changes. For example (from the JassHelper manual):
JASS:
//! textmacro GetSetHandle takes TYPE, TYPENAME
        function GetHandle$TYPENAME$ takes handle h, string k returns $TYPE$
            return GetStoredInteger(udg_handlevars, I2S(H2I(h)), k)
            return null
        endfunction
        function SetHandle$TYPENAME$ takes handle h, string k, $TYPE$ v returns nothing
            call StoredInteger(udg_handlevars,I2S(H2I(h)),k, H2I(v))
        endfunction
    //! endtextmacro

    //! runtextmacro GetSetHandle("unit","Unit")
    //! runtextmacro GetSetHandle("location","Loc")
    //! runtextmacro GetSetHandle("item","Item")


That is the basic handle vars simplified into a textmacro. Now for the syntax:

JASS:
//! textmacro <name> takes <var1>, <var2>, <etc>


This declares the start of a textmacro. It doesn't necessarily have to take anything, in which case you leave out 'takes'.

JASS:
$<var1>$


Dollarsigns are used for the variables you defined in the textmacro declaration.

JASS:
//! endtextmacro


The end of a textmacro declaration.

JASS:
//! runtextmacro <name>("var1", "var2", etc)


This line actually runs the textmacro, inserting the code you typed within the textmacro declaration into the script at this point and replacing the variables with the strings you pass it.

Hope I've helped.

NB: I've used <> to signify where you insert your own code. Do not type <> within the textmacro, you will get a syntax error.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top