| 06-25-2009, 03:00 AM | #1 |
Okay, I can use scopes and libraries just fine, but I'm seeing textmacros be used more and more, yet I have no idea what exactly they are for. What is it? If it's too complicated to explain what exactly it is, I would just like to know what people use it for. I know that UnitProperties uses it, but I can't really use it if I don't know what textmacros are. |
| 06-25-2009, 03:19 AM | #2 |
For example you have a set of functions which share a similar (repetitive) shape but changes some argument types or parts of them, then you can use a textmacro to save writing time. 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") (the example will be deprecated when patch 1.24 becomes release) As you can see, instead of writing the same for unit, location and item, we set the template of the functions and jassHelper will write the code for us. |
| 06-25-2009, 03:34 AM | #3 |
textmacro is a way to write code easily by reducing the encryption of codes with iterated structure to a single line. a general structure of code is designated with its significant variable elements defined. the structure is iterated in its every implementation, with different valuations of the significant variable elements according to incident. the elements are arguments of the textmacro as strings: the encryption of the code you would write. textmacro aTextmecro takes (structure)element1, element2, element3, ..., elementN example: //declare JASS://!textmacro aTextmacro takes type, name //code of textmacro starts here globals $type$ $name$ endglobals //code of textmacro ends here //declare end //!endtextmacro example: JASS://! runtextmacro aTextmacro("integer", "myIntegerVariable") JASS:globals integer myIntegerVariable endglobals example2: JASS://! runtextmacro aTextmacro("real", "myRealVariable") JASS:globals real myRealVariable endglobals the code structures in both examples are instances or incidents of the general structure: JASS:globals $type$ $name$ //declaration of global variable with such a type and such a name endglobals so textmacro just make it easier to write things |
| 06-25-2009, 03:47 PM | #4 |
Oh, thanks you guys. I keep forgetting that the JassHelper Manual exists... I will read it thoroughly later. It will be able to explain to me what structs are and how to use them (I've messed that one up too many times to count). I especially like this example: JASS://! textmacro bye call BJDebugMsg("1") call BJDebugMsg("2") call BJDebugMsg("3") //! endtextmacro function test takes nothing returns nothing //! runtextmacro bye() //! runtextmacro bye() endfunction Hmm... Does this mean that I can use a textmacro to make private globals, too? And, by the looks it, it may be able to make structs, too? Er... I don't know, though. By the looks it, it looks like I'd have to use hundreds of textmacros to actually make it worthwhile in saving space (like UnitProperties). Unless every byte of code truly counts. I was thinking of using textmacros like the above as a general variable template for repetitive things (like spells), but if I have to set each variable with a line of code, I'm not really saving space... Or am I? I guess textmacros are for convenience and/or saving space depending what it's used for. Well, in that case, I suppose textmacros are for much bigger things, which may explain why they are coming up more often. Okay, I guess I understand. Thanks. |
| 06-25-2009, 03:55 PM | #5 |
textmacros are just a way to do copy and paste automatically. You 'can' have private globals inside textmacros, as long as the place in which you run the textmacro allows private globals. This logic works for just about everything... They are also very good at making your code ugly. |
