This article is a stub, you can help the RPTools Wiki project by contributing content to expand this article.
This article needs: Could use examples of the ignoreOutput and newScope parameters.
Note: This function can only be used in a Trusted Macro
Defines a user function that can be used anywhere that core functions can be used. A user defined function is a link to another macro. A special macro labeled onCampaignLoad is useful for defining functions upon the loading of your campaign. This because the function will be defined AFTER the macro has been run. In case of onCampaignLoad, that macro is always run when the campaign is loaded. This saves you the hassle of manually requiring to run this macro to enable the definition.
defineFunction(function, macro, ignoreOutput)
defineFunction(function, macro, ignoreOutput, newScope)
function- The name of the user defined function to be defined.
macro- The name and location of the macro that is called when the user defined function is used.
ignoreOutput- If the defined function should ignore all output and only return the value of
macro.return, defaults to
newScope- If the defined function should create a new variable scope when executed, defaults to
1). A new variable scope means that the defined function can only read the variables of the macro that called it; if you do not create a new scope the defined function can read, update, and create variables in its parent's variable scope. Updating variables in the parent's scope includes over-writing any parameters that a parent might have stored within arg(), if a user-defined function that does not create a new scope is called within another user-defined function.
[h: defineFunction("character.heal", "heal@Lib:Character")]
Defines a function
character.heal() which calls
heal@Lib:Character when evoked. Note that in this case there must exist a function called "heal" on a token called "lib:Character". The advantage of using the prefix "lib:" on the token name is that it becomes a "lib:token" which is accessible from ANY map instead of only the map you happen to have active.
Should you pass on any arguments e.g.
[h: character.heal("hello", "hi")]
then these parameters can be accessed inside
character.heal() by using
[h: firstArg = arg(0)]
[h: theOtherOne = arg(1)]
- 1.3b56 - Added