macroLink: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(37 intermediate revisions by 14 users not shown)
Line 1: Line 1:
==Function macroLink==
{{MacroFunction
|name=macroLink
|version=1.3b48
|description=
Creates the HTML for a link which will run the specified macro when clicked on in a [[frame_(roll_option)|frame]], [[dialog_(roll_option)|dialog]], or the chat window.  Additionally, if you send the link to the chat window, it will automatically be executed by any recipients as soon as they receive it.  This can be useful for popping up or updating [[frame_(roll_option)|frames]] or [[dialog_(roll_option)|dialogs]] for your players.  To auto-execute in the chat window, it must not be hidden by roll options like {{roll|h}}, but may be hidden by being contained within an HTML comment.<br/>
'''Some notes on the auto execution'''
*If you refer to a macro on a lib:token it will automatically execute, however if you refer to a macro on the campaign panel, the macro is NOT automatically executed when sent to the chat.
*It will also not work if the owner of the lib:token is not an (online) GM, though as a general practice its best not to set ownership of lib:tokens at all.
*To prevent the macro from automatically executing you can turn off the 'auto execute' in the edit panel of the macro that you're linking to.
&nbsp;


Creates the HTML for a link which will run the specified macro when clicked on.
|usage=
<syntaxhighlight lang="mtmacro" line>
macroLink(text, macroName)
</syntaxhighlight>
<syntaxhighlight lang="mtmacro" line>
macroLink(text, macroName, output)
</syntaxhighlight>
<syntaxhighlight lang="mtmacro" line>
macroLink(text, macroName, output, args)
</syntaxhighlight>
<syntaxhighlight lang="mtmacro" line>
macroLink(text, macroName, output, args, target)
</syntaxhighlight>
<br/>The string generated by the {{code|macroLink()}} function follows this format:<syntaxhighlight lang="html4strict">
<a href="macro://macroName/output/target?args">text</a>
</syntaxhighlight>
'''Parameters'''
{{param|text|is the text to display for the link.}}
{{param|macroName|is the name of the macro to run when the link is clicked. The {{code|macroName}} is in the same format that is used for [[Macros:Branching_and_Looping#MACRO_Option |[macro(...): ...] ]]  e.g. {{code|Test@Lib:test}}.}}
{{param|output|contains who the output of the macro should go to, values are (defaults to {{code|"none"}}):}}
** {{code|"self"}} - Display only to person who clicked on the link.
** {{code|"gm"}} - Display to GM.
** {{code|"all"}} - everyone (acts like a [[Chat Commands#say|/say]]).
** {{code|"none"}} - discard any output.
** {{code|"gm-self"}} - Display to GM and the person executing the link.
** {{code|"list"}} - Displays to a list of players. When the {{code|output}} is set to {{code|"list"}} then the macro link expects the {{code|args}} parameter to be a [[JSON Object]], that contains a field called {{code|mlOutputList}} which is a [[JSON Array]] containing the players to send the output to.
{{param|args|Any arguments to be passed to the macro when it is called.}}
{{param|target|Which tokens to run the macro on. Target can be one or more of the following separated by commas (defaults to {{code|"impersonated"}}):}}
** {{code|"impersonated"}} - the impersonated [[Token]].
** {{code|"selected"}} - the selected [[Token]]s.
** {{code|"Token Id"}} - the ''id'' of a [[Token]].


|examples=
* To create a link that will call a macro called {{code|Test}} on the [[Token:library_token|Library Token]] named {{code|Lib:Test}} that says "''Click on me!''" and displays the output to the GM.
<syntaxhighlight lang="mtmacro">
[r: macroLink("Click on me!", "Test@Lib:Test", "gm", "count=6", "impersonated")]
</syntaxhighlight><br/>
produces this output:<syntaxhighlight lang="html4strict"><a href="macro://Test@Lib:Test/gm/impersonated?count=6;">Click on me!</a></syntaxhighlight><br/>
* Sending to multiple players and the GM in 1.3b55
<syntaxhighlight lang="mtmacro" line>
[h: outputTo = '["Fred", "Barney", "gm"]']
[h: args = json.set("{}", "mlOutputList", outputTo)]
[r: macroLink("Click on me!", "Test@Lib:Test", "list", args)]
</syntaxhighlight><br/>
* Updating a character sheet [[frame_(roll_option)|frame]] without displaying the link:
<syntaxhighlight lang="mtmacro">
Took 4 points of damage.<!-- [r: macroLink("Update Character Sheet", "Update Character Sheet@Lib:Test")] -->
</syntaxhighlight><br/>
* An example of a longer custom macrolink:
This is a link that is user created to send several variables to the AttackMacro. Each variable must be separated by a {{code|&}} sign. Spaces within text must be replaced with a {{code|+}} sign. Plus sign can't be sent, you might want to use the html code for plus sign ({{code|&27;}}) instead of {{code|+}}.
<syntaxhighlight lang="html4strict"><a href="macro://AttackMacro@Lib:Test/all/impersonated?Count=6&DiceToRoll=1d6plus4&Text=Hello+there+Im+attacking+you;">Click me</a></syntaxhighlight>


'''How to call a macro on a non-library token'''


You can call macros on usual tokens by using {{code|@TOKEN}} in the macro name. You have to specify the token with the macro as target token. The usual limits of ownership and trust should be expected here too.


===Usage===
This line would call macro {{code|B}} on token {{code|Hero}}:
<source lang="mtmacro" line>
[r: = macroLink(text, macro)]
[r: = macroLink(text, macro, output, args)]
[r: = macroLink(text, macro, output, args)]
[r: = macroLink(text, macro, output, args, target)]
</source>


<syntaxhighlight lang="mtmacro">
[r: macroLink("Click me!", "B@TOKEN", "all", "", findToken("Hero"))]
</syntaxhighlight>


* ''text'' is the text to display for the link.
'''UDFs and Macro Links'''
* ''macro'' is the name of the macro to run when the link is clicked.
The macro is in the same format that is used for [[Macros:Roll:macro |[macro(...): ...] ]]
e.g. Test@Lib:test
* ''output'' contains who the output of the macro should go to, values are (defaults to none)
** ''self'' - Display only to person who clicked on the link.
** ''gm'' - Display to GM.
** ''all'' - everyone (acts like a [[SlashCommands:say|/say]])
** ''none'' - discard any output.
* ''args'' Any arguments to be passed to the macro when it is called.
* ''target'' Which tokens to run the macro on. Target can be one or more of the following (separated by ",")
** ''impersonated'' - the impersonated [[Token:Token|Token]]
** ''selected'' - the selected [[Token:Token|Token]]s
** ''[[Token:Token Id|Token Id]]'' - the ''[[Token:Token Id|id]] of a [[Token:Token|Token]].


===Examples===
UDFs (user defined functions - see {{func|defineFunction}}) and macro links are just two different ways of doing the same thing. They both call a macro and pass arguments. The UDF expresses it as functionName(arg0,arg1,...) while a macrolink may express it as macroLink(text, macroName, output, args, target) where args is a string prop list (ie "arg0=0; arg1=1; ..."). How the args are processed in the macro are shown as different, but they're only different in procedure, not functionality.
To create a link that will call a macro called Test on the [[Token:LibToken|Lib:Token]] named Lib:Test that says "''click on me''" and displays the output to the GM.
 
<source lang="mtmacro" line>
I could for example make a UDF call functionName(arg0) where arg0 is "arg0=0; arg1=1;" OR I could make a macroLink where the args are in a json array like macroLink(text, macroName, output, '["arg0":1,"arg1":1]', target) and then the called macro could process the arguments the same way if called from a macroLink or a UDF.
[r: macroLink("click on me", "Test@Lib:Test", "", "gm")]
 
</source>
In either case, the called macro will receive macro.args with the value you sent. The {{func|arg}} function will look at what's in macro.args and if it looks like a json array, then it will parse out the arguments in to the arg(0), arg(1)... variables.
 
|also=
{{func|macroLinkText}}
 
|changes=
{{change|1.3b55|Added {{code|gm-self}} and {{code|list}} output options.}}
{{change|1.3b56|Links created using this function will no longer show a tooltip when displayed in a dialog or frame.}}
}}
[[Category:Miscellaneous Function]]

Latest revision as of 23:59, 25 April 2023

macroLink() Function

Introduced in version 1.3b48
Creates the HTML for a link which will run the specified macro when clicked on in a frame, dialog, or the chat window. Additionally, if you send the link to the chat window, it will automatically be executed by any recipients as soon as they receive it. This can be useful for popping up or updating frames or dialogs for your players. To auto-execute in the chat window, it must not be hidden by roll options like [h:], but may be hidden by being contained within an HTML comment.

Some notes on the auto execution

  • If you refer to a macro on a lib:token it will automatically execute, however if you refer to a macro on the campaign panel, the macro is NOT automatically executed when sent to the chat.
  • It will also not work if the owner of the lib:token is not an (online) GM, though as a general practice its best not to set ownership of lib:tokens at all.
  • To prevent the macro from automatically executing you can turn off the 'auto execute' in the edit panel of the macro that you're linking to.
 

Usage

macroLink(text, macroName)
macroLink(text, macroName, output)
macroLink(text, macroName, output, args)
macroLink(text, macroName, output, args, target)


The string generated by the macroLink() function follows this format:

<a href="macro://macroName/output/target?args">text</a>

Parameters

  • text - is the text to display for the link.
  • macroName - is the name of the macro to run when the link is clicked. The macroName is in the same format that is used for [macro(...): ...] e.g. Test@Lib:test.
  • output - contains who the output of the macro should go to, values are (defaults to "none"):
    • "self" - Display only to person who clicked on the link.
    • "gm" - Display to GM.
    • "all" - everyone (acts like a /say).
    • "none" - discard any output.
    • "gm-self" - Display to GM and the person executing the link.
    • "list" - Displays to a list of players. When the output is set to "list" then the macro link expects the args parameter to be a JSON Object, that contains a field called mlOutputList which is a JSON Array containing the players to send the output to.
  • args - Any arguments to be passed to the macro when it is called.
  • target - Which tokens to run the macro on. Target can be one or more of the following separated by commas (defaults to "impersonated"):
    • "impersonated" - the impersonated Token.
    • "selected" - the selected Tokens.
    • "Token Id" - the id of a Token.

Examples

* To create a link that will call a macro called Test on the Library Token named Lib:Test that says "Click on me!" and displays the output to the GM.
[r: macroLink("Click on me!", "Test@Lib:Test", "gm", "count=6", "impersonated")]

produces this output:
<a href="macro://Test@Lib:Test/gm/impersonated?count=6;">Click on me!</a>

  • Sending to multiple players and the GM in 1.3b55
[h: outputTo = '["Fred", "Barney", "gm"]']
[h: args = json.set("{}", "mlOutputList", outputTo)]
[r: macroLink("Click on me!", "Test@Lib:Test", "list", args)]

  • Updating a character sheet frame without displaying the link:
Took 4 points of damage.<!-- [r: macroLink("Update Character Sheet", "Update Character Sheet@Lib:Test")] -->

  • An example of a longer custom macrolink:

This is a link that is user created to send several variables to the AttackMacro. Each variable must be separated by a & sign. Spaces within text must be replaced with a + sign. Plus sign can't be sent, you might want to use the html code for plus sign (&27;) instead of +.

<a href="macro://AttackMacro@Lib:Test/all/impersonated?Count=6&DiceToRoll=1d6plus4&Text=Hello+there+Im+attacking+you;">Click me</a>

How to call a macro on a non-library token

You can call macros on usual tokens by using @TOKEN in the macro name. You have to specify the token with the macro as target token. The usual limits of ownership and trust should be expected here too.

This line would call macro B on token Hero:

[r: macroLink("Click me!", "B@TOKEN", "all", "", findToken("Hero"))]

UDFs and Macro Links

UDFs (user defined functions - see defineFunction()) and macro links are just two different ways of doing the same thing. They both call a macro and pass arguments. The UDF expresses it as functionName(arg0,arg1,...) while a macrolink may express it as macroLink(text, macroName, output, args, target) where args is a string prop list (ie "arg0=0; arg1=1; ..."). How the args are processed in the macro are shown as different, but they're only different in procedure, not functionality.

I could for example make a UDF call functionName(arg0) where arg0 is "arg0=0; arg1=1;" OR I could make a macroLink where the args are in a json array like macroLink(text, macroName, output, '["arg0":1,"arg1":1]', target) and then the called macro could process the arguments the same way if called from a macroLink or a UDF.

In either case, the called macro will receive macro.args with the value you sent. The arg() function will look at what's in macro.args and if it looks like a json array, then it will parse out the arguments in to the arg(0), arg(1)... variables.

See Also

Version Changes

  • 1.3b55 - Added gm-self and list output options.
  • 1.3b56 - Links created using this function will no longer show a tooltip when displayed in a dialog or frame.