There's a PDF that Craig put together that has a decent illustration of how they work, but the basic approach is this: normally, you'd call another macro, and you can pass it an argument. The argument can be a string, a number, a JSON object, whatever - it gets sent over to the called macro. You do that with:toyrobots wrote:Point me to an explanation of User-Defined Functions in Macros?Rumble wrote:zEal wrote:If it's something you're going to do more than once with little variation, create a user defined function.
This is something I rarely do, and should probably do more, but I never saw a substantial need.
Code: Select all
[macro("MacroName@Lib:Token"):arguments]
Code: Select all
[defineFunction("funcName", "MacroName@Lib:Token")]
Code: Select all
[funcName(arguments)]
Code: Select all
[funcName(argument1, argument2, argument3)]
The two benefits:
1. It's easier to write than [macro("macroname@lib:token"):yadda]
2. You can pass multiple arguments easily, just by specifying them. The magic that handles that transfer is inside maptool somewhere; you don't have to worry about it.
The reason I haven't used it is that I've written my macros to pass single arguments (usually, JSON objects) so the only benefit is benefit 1, which wasn't sufficient to get me to rewrite everything. When I do a rewrite, I'll probably plan it out using user-defined functions carefully.