broadcast: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
No edit summary
m (Text replacement - "<source" to "<syntaxhighlight")
 
(41 intermediate revisions by 8 users not shown)
Line 1: Line 1:
{{MacroFunction
{{MacroFunction


|name=broadcast |trusted=true |version=1.3b77 |description=
|name=broadcast
 
|trusted=true
{{stub|Examples}}
|version=1.3b77
 
|description=
This function lets send you a message directly to the chat area of another/all connected maptool clients. It does not display the senders name or token image in front of the message.
Sends a message in the chat area to either all connected MapTool clients (default), or a subset of player names and/or keywords like {{code|"gm"}} given in a string list or JSON array. Broadcast does not display the sender's name or token image in front of the message.
 
It lets send you a message either to all or a list of players - use the player names or the keyword "gm". As delimiter you can specify either a string list separator character or "json" if you specify the target list as json array. The big difference between a 'normal' chat message is: 1. if the message is part of a macro then the message is send even if the macro is aborted(after the broadcast). 2. the sender of the message is NOT displayed and 3. if you broadcast an {{func|execLink}} then that macro is AUTOMATICALLY executed on the clients its broadcasted to, with the exception to the client that sends the message!


The big differences between broadcast and a normal chat message are:
#  if the message is part of a macro, then the message is sent even if the macro is aborted (after the broadcast),
#  the message sender's name and token image are NOT displayed, and
#  if you broadcast an {{func|execLink}}, then that macro is AUTOMATICALLY executed on the clients it's broadcasted to, with the exception of the client that sends the message!
&nbsp;
|usage=  
|usage=  
<source lang="mtmacro" line> broadcast(message, [targets], [delimiter]) </source> }}
<syntaxhighlight lang="mtmacro" line> broadcast(message, [targets], [delimiter]) </syntaxhighlight>
[[Category:Miscellaneous Function]]
[[Category:Miscellaneous Function]]


'''Parameters'''
'''Parameters'''
{{param|message|a message that is broadcasted to the users that are listed as parameters.}}
{{param|message|a message that is broadcasted to the users that are listed as parameters.}}
{{param|targets|are the user names (so not token names) but the names of the users that are logged in. "gm" is also a valid parameter to give}}. E.g.: "tim, tom, tarra". Defaults to all players (so if no parameter is given the message is send to all players).}}
{{param|targets|a String list or JSON array of Player names, not Token names. Also recognizes: "gm", "gm-self", "self", "none", "all", "not-gm", "not-self", and "not-gm-self" as valid parameters. Defaults to all players (so if no parameter is given the message is send to all players). Note that {{code|targets}} is inclusive, so setting it to "not-gm, gm" will send the message to all connected players - all non-GMs and all GMs.}}
{{param|delim|The delimiter used to separate the values in the String List that is returned, defaults to {{code|","}}. If {{code|"json"}} is specified, a JSON array is returned instead of a String List.}}
{{param|delim|The delimiter used to separate the values in the String List that is given, defaults to {{code|","}}. If {{code|"json"}} is specified, a JSON array is expected instead of a String List.}}


|example=
|examples=
&nbsp;
*Sending a message to all players:
*Sending a message to all players:
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: broadcast("Hello World")]
[h: broadcast("Hello World")]
</source><br />
</syntaxhighlight><br />
*Sending a message to gm only:
*Sending a message to all GMs only:
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: broadcast("Hello World", "gm")]
[h: broadcast("Hello World", "gm")]
</source><br />
</syntaxhighlight><br />
*Sending a message to tim and tom only:
*Sending a message to "tim" and "tom" only (default comma delimiter):
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: broadcast("Hello World", "tim, tom")]
[h: broadcast("Hello World", "tim, tom")]
</source><br />
</syntaxhighlight><br />
*Using the json as delimiter:
*Using json as the delimiter:
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: broadcast("Hello World", '["tim", "tom"]')]
[h: broadcast("Hello World", '["tim", "tom"]')]
</source><br />
</syntaxhighlight> or
*Executing the macro 'update()' located at 'lib:Token', for the token 'Dragon' on the client PC of 'Tim':
<syntaxhighlight lang="mtmacro" line>
<source lang="mtmacro" line>
[h: broadcast("Hello World", json.append("", "tim", "tom"))]
</syntaxhighlight><br />
*Executing the macro {{code|update()}} located at {{code|lib:Token}}, for the token {{code|Dragon}} on the PC of user {{code|Tim}}:
<syntaxhighlight lang="mtmacro" line>
[h: link = macroLinkText("update@Lib:Token", "none", "", "Dragon")]
[h: link = macroLinkText("update@Lib:Token", "none", "", "Dragon")]
[h: broadcast(execLink(link), "tim")]
[h: broadcast(execLink(link), "tim")]
</source><br />
</syntaxhighlight><br />
 
|changes=
{{change|1.5.5|Added the {{code|gm-self}}, {{code|self}}, {{code|all}}, and {{code|none}} options to  {{code|targets}}.}}
{{change|1.5.7|Added the {{code|not-gm-self}}, {{code|not-self}}, and {{code|not-gm}} options to  {{code|targets}}.}}
}}

Latest revision as of 23:59, 14 March 2023

broadcast() Function

 Note: This function can only be used in a Trusted Macro

Introduced in version 1.3b77
Sends a message in the chat area to either all connected MapTool clients (default), or a subset of player names and/or keywords like "gm" given in a string list or JSON array. Broadcast does not display the sender's name or token image in front of the message.

The big differences between broadcast and a normal chat message are:

  1. if the message is part of a macro, then the message is sent even if the macro is aborted (after the broadcast),
  2. the message sender's name and token image are NOT displayed, and
  3. if you broadcast an execLink(), then that macro is AUTOMATICALLY executed on the clients it's broadcasted to, with the exception of the client that sends the message!
 

Usage

 broadcast(message, [targets], [delimiter])

Parameters

  • message - a message that is broadcasted to the users that are listed as parameters.
  • targets - a String list or JSON array of Player names, not Token names. Also recognizes: "gm", "gm-self", "self", "none", "all", "not-gm", "not-self", and "not-gm-self" as valid parameters. Defaults to all players (so if no parameter is given the message is send to all players). Note that targets is inclusive, so setting it to "not-gm, gm" will send the message to all connected players - all non-GMs and all GMs.
  • delim - The delimiter used to separate the values in the String List that is given, defaults to ",". If "json" is specified, a JSON array is expected instead of a String List.

Examples

 
  • Sending a message to all players:
[h: broadcast("Hello World")]

  • Sending a message to all GMs only:
[h: broadcast("Hello World", "gm")]

  • Sending a message to "tim" and "tom" only (default comma delimiter):
[h: broadcast("Hello World", "tim, tom")]

  • Using json as the delimiter:
[h: broadcast("Hello World", '["tim", "tom"]')]
or
[h: broadcast("Hello World", json.append("", "tim", "tom"))]

  • Executing the macro update() located at lib:Token, for the token Dragon on the PC of user Tim:
[h: link = macroLinkText("update@Lib:Token", "none", "", "Dragon")]
[h: broadcast(execLink(link), "tim")]

Version Changes

  • 1.5.5 - Added the gm-self, self, all, and none options to targets.
  • 1.5.7 - Added the not-gm-self, not-self, and not-gm options to targets.