Textmacros

Waaaaagh

I lost all my rep and my title being a jerk
Reaction score
70
Anyway to track usage of runtextmacro ?

JASS:
//! textmacro X takes A
    
    struct Struct
        unit G_Unit
        trigger t
    endstruct

    function $A$_Actions takes nothing returns nothing
        local Struct s=GetStructA(GetTriggeringTrigger())
        call RemoveUnit(s.G_Unit)
    endfunction

    function Init_$A$ takes nothing returns nothing
        local Struct s=Struct.create()
        set s.t=CreateTrigger()
        set s.G_Unit=$A$
        call SetStructA(s.t,s)
        call TriggerRegisterUnitEvent(s.t,G_Unit,EVENT_UNIT_DEATH)
        call TriggerAddAction(s.t,$A$_Actions)
    endfunction

    //! noparse
    function InitTrig_Trig1 takes nothing returns nothing
        //! endnoparse
        call Init_$A$ 
        //! noparse
        //This would be done once for each time the textmacro is run.
        //However, I cannot include this in the textmacro,
       //as it would copy the InitTrig a bunch.
    endfunction
    //! endnoparse

//! endtextmacro

//! runtextmacro X("gg_unit_hfoo_0000")


Is there something like [NoParse][NoParse][/NoParse][/NoParse] for vJass?
A feasible work around option is cool too.
 

Ghan

Administrator - Servers are fun
Staff member
Reaction score
888
> Anyway to track usage of runtextmacro ?

Track? You mean count the uses of?

Excuse my noob not-knowing-wtf-textmacros-are ways, but could you not just use a global variable that gets increased by one every time it's run?
 

Waaaaagh

I lost all my rep and my title being a jerk
Reaction score
70
The issue: Adding multiple textmacros to something that is run once. Textmacros just take text and copy it into wherever you run the textmacro. However, you cannot put any function names inside a textmacro that don't use something the textmacro takes, else the function will be redeclared. Textmacros are just for lazy people (so you don't have to right out a bunch of similar functions), but there are other uses as well.

The problem with //! runtextmacro is that nothing is actually run. It is simply like pressing Paste, after having copied the textmacro's text. So, you could have a "set MacroCount=MacroCount+1" in there, but it wouldn't get run, it would just be there. However, if I can get a part of a textmacro into an InitTrig function, then I can call the rest of the textmacro from there, and it will get run. The issue is with copying the InitTrig function (You can't do that - it's bad).
 

Ghan

Administrator - Servers are fun
Staff member
Reaction score
888
But when you do the runtextmacro, can't you increase a variable there? I guess it's outside of a function, though....

I'd better get out of here before my brain explodes and leaks out of my ears onto the desk. :p
 

phyrex1an

Staff Member and irregular helper
Reaction score
447
Why are you using textmacros for that anyway?

JASS:
    struct Struct
        unit G_Unit
        trigger t
    endstruct

    function UnitActions takes nothing returns nothing
        // I suppose that you know that s.G_Unit == GetTriggerUnit() ?
        local Struct s=GetStructA(GetTriggeringTrigger())
        call RemoveUnit(s.G_Unit)
    endfunction

    function InitUnit takes unit u returns nothing
        local Struct s=Struct.create()
        set s.t=CreateTrigger()
        set s.G_Unit= u
        call SetStructA(s.t,s)
        call TriggerRegisterUnitEvent(s.t,G_Unit,EVENT_UNIT_DEATH)
        // I think that the preferred way to create dynamic triggers with actions is to use conditions as actions,
        call TriggerAddAction(s.t,UnitActions)
    endfunction


If that just was a (very bad) example then I think the answer is to use two textmacros like:

JASS:
//! textmacro X takes A
function $A$_Init takes nothing returns nothing
endfunction
//! endtextmacro

//! textmacro Y takes A
call $A$_Init()
//! endtextmacro

//! runtextmacro X("gg_unit_hfoo_0000")
//! runtextmacro X("gg_unit_hfoo_0001")
function Init takes nothing returns nothing
//! runtextmacro Y("gg_unit_hfoo_0000")
//! runtextmacro Y("gg_unit_hfoo_0001")
endfunction
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top