Difference between revisions of "Mod:Chat"
From Roll20 Wiki
Andreas J. (Talk | contribs) m (→API Command Buttons) |
Andreas J. (Talk | contribs) |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 5: | Line 5: | ||
'''chat:message''' | '''chat:message''' | ||
− | Triggered whenever a new chat message is received. Note that if the message is of type | + | Triggered whenever a new chat message is received. Note that if the message is of type {{c|rollresult}} or {{c|gmrollresult}}, you will need to call <code>JSON.parse()</code> on the content of the message to get an object which contains information on the roll results. |
− | ''Note:'' If a player enters a chat message beginning with an exclamation mark (!), that message will have the type of "api" and not be shown to anyone. It's intended that this functionality can be used to provide commands that | + | ''Note:'' If a player enters a chat message beginning with an exclamation mark (!), that message will have the type of "api" and not be shown to anyone. It's intended that this functionality can be used to provide commands that Mod scripts respond to. So, if the message is of type "api", then it hasn't been shown to anyone, and the player who sent the chat message is probably expecting an Mod script to do something as a result of the message. |
Callback parameter: | Callback parameter: | ||
Line 568: | Line 568: | ||
* <code>noarchive</code> -- set this to true to prevent the message from being stored in the chat log. This is particularly useful for output that is not part of the story, such as API Button menus and state information. | * <code>noarchive</code> -- set this to true to prevent the message from being stored in the chat log. This is particularly useful for output that is not part of the story, such as API Button menus and state information. | ||
− | * <code>use3d</code> -- You can now generate [[3D Dice]] rolls using the sendChat() function. The syntax is simply: <code>sendChat("Name", "Rolling <nowiki>[[3d6]]</nowiki>", null, {use3d: true});</code> If you pass a player ID to the name parameter, such as <code>sendChat("player|-ABC123",...)</code> the player's color will be used for the dice. Otherwise a default white color will be used. <br>'''Note:''' Clients can only show the result of one 3D roll at a time, so making a bunch of separate 3D rolls in a row is not useful. Also note that using 3D rolls does place a bit more strain on the [[QuantumRoll]] server, so use your judgement and don't perform 100 3D rolls in the space of a second. Use 3D rolls when the roll will "matter" to the player and make an impact on the game. | + | * <code>use3d</code> -- You can now generate [[3D Dice]] rolls using the sendChat() function. The syntax is simply: <code>sendChat("Name", "Rolling <nowiki>[[3d6]]</nowiki>", null, {use3d: true});</code> If you pass a player ID to the name parameter, such as <code>sendChat("player|-ABC123",...)</code> the player's color will be used for the dice. Otherwise a default white color will be used. <br>'''Note:''' Clients can only show the result of one 3D roll at a time, so making a bunch of separate 3D rolls in a row is not useful. Also note that using 3D rolls does place a bit more strain on the [[QuantumRoll]] server, so use your judgement and don't perform 100 3D rolls in the space of a second. Use 3D rolls when the roll will "matter" to the player and make an impact on the game. '''Warning:''' The use3d parameter does not seem to be working as of July 2021, c.f.: https://app.roll20.net/forum/post/9017606/slug%7D. |
If you want to adjust these options but do not want to use a <code>callback</code> parameter (third parameter--see above), you can simply pass <code>null</code> in it's place: | If you want to adjust these options but do not want to use a <code>callback</code> parameter (third parameter--see above), you can simply pass <code>null</code> in it's place: | ||
Line 593: | Line 593: | ||
====Entering API Buttons In Chat==== | ====Entering API Buttons In Chat==== | ||
− | You can also type Markdown syntax API buttons into chat for others to use. Because they will be interpreted by the chat parser, if you want attributes, queries and rolls to be expanded when the button is clicked, you must enter parts of the command with a special syntax ([[ | + | You can also type Markdown syntax API buttons into chat for others to use. Because they will be interpreted by the chat parser, if you want attributes, queries and rolls to be expanded when the button is clicked, you must enter parts of the command with a special syntax ([[HTML Entities]]): |
{| class="wikitable" | {| class="wikitable" | ||
Line 637: | Line 637: | ||
====More==== | ====More==== | ||
− | * https://app.roll20.net/forum/post/10798001/looking-for-workaround-special-characters-in-api-buttons April 2022 | + | * [https://app.roll20.net/forum/post/10798001/looking-for-workaround-special-characters-in-api-buttons looking-for-workaround-special-characters-in-api-buttons April 2022] |
==See Also== | ==See Also== |
Latest revision as of 08:35, 9 June 2024
Page Updated: 2024-06-09 |
Attention: This page is community-maintained. For the official Roll20 version of this article, see the Help Center for assistance: Here .
This is related to Mods, which require Pro info to be able to use.Main Page: Mod:Development |
Roll20 Mod
Use Mods
- Use & Install
- Mod:Script Index & Suggestions
- Short Community Scripts
- Meta Scripts
- User Documentation
- Mod Scripts(Forum)
- Mod Update 2024🆕
- Macro Guide
Mod Development
Reference
- Objects
- Events
- Chat Events & Functions
- Utility Functions
- Function
- Roll20 object
- Token Markers
- Sandbox Model
- Debugging
Cookbook
Contents |
[edit] Chat Events
chat:message
Triggered whenever a new chat message is received. Note that if the message is of type rollresult
or gmrollresult
, you will need to call JSON.parse()
on the content of the message to get an object which contains information on the roll results.
Note: If a player enters a chat message beginning with an exclamation mark (!), that message will have the type of "api" and not be shown to anyone. It's intended that this functionality can be used to provide commands that Mod scripts respond to. So, if the message is of type "api", then it hasn't been shown to anyone, and the player who sent the chat message is probably expecting an Mod script to do something as a result of the message.
Callback parameter:
Property | Default Value | Notes |
---|---|---|
who | "" | The display name of the player or character that sent the message. |
playerid | The ID of the player that sent the message. | |
type | "general" | One of "general", "rollresult", "gmrollresult", "emote", "whisper", "desc", or "api". |
content | "" | The contents of the chat message. If type is "rollresult", this will be a JSON string of data about the roll.
|
origRoll | (type "rollresult" or "gmrollresult" only) The original text of the roll, eg: 2d10+5 fire damage when the player types /r 2d10+5 fire damage . This is equivalent to the use of content on messages with types other than "rollresult" or "gmrollresult".
| |
inlinerolls | (content contains one or more inline rolls only) An array of objects containing information about all inline rolls in the message. | |
rolltemplate | (content contains one or more roll templates only) The name of the template specified. | |
target | (type "whisper" only) The player ID of the person the whisper is sent to. If the whisper was sent to the GM without using his or her display name (ie, /w gm text instead of /w Riley text when Riley is the GM), or if the whisper was sent to a character without any controlling players, the value will be "gm".
| |
target_name | (type "whisper" only) The display name of the player or character the whisper was sent to. | |
selected | (type "api" only) An array of objects the user had selected when the command was entered. |
Note: You probably don't need all of this information. In most cases you'll only be interested in the overall result of the roll (see the bottom of the first example). However all of it is provided if you want to really dig deeper into the results of a roll.
Roll Result Structure Example 1
After you call JSON.parse
on the content
property of a "rollresult" or "gmrollresult" message, you'll get an object with the following format (this is the result from the command /roll {2d6}+5+1t[weather] Attack!
)
{ "type":"V", //"V" = "Validated Roll" (this will always be "V" right now) "rolls": [ { "type":"G", //"G" indicates a grouped roll. A group is like a series of "sub-rolls" within a roll. "rolls": [ [ { "type":"R", //"R" = "Roll" "dice":2, // Number of dice rolled (2dX means 2 dice) "sides":6, //Number of sides for the dice (Xd6 means 6 sides) "mods":{}, "results": [ //An array of the results of each roll. { "v":1 // We rolled a 1 for our first 2d6 }, { "v":5 //We rolled a 5 for our second 2d6 } ] } ] ], "mods":{}, "resultType":"sum", //The result is a sum (as opposed to a success check) "results": [ { "v":6 // In this case, the overall result (total) of the group. } ] }, { "type":"M", //"M" = Math Expression "expr":"+5+" }, { "type":"R", //"R" = Roll "dice":1, "table":"weather", //The table property is set to the name of the table used if this roll was made against a table "mods":{}, "sides":2, //You can probably just ignore this for table rolls. "results": [ { "v":0, //The "value" of the table item rolled. For text tables this is always 0. "tableidx":1, //The index of the item in the table that was rolled. "tableItem": { //A copy of the table item object as it existed when the table was rolled. "name":"rainy", "avatar":"", //This will be a URL to an image if the rollable table uses image icons "weight":1, "id":"-IpzPx2j_9piP09ceyOv" } } ] }, { "type":"C", // "C" = Comment "text":" Attack!" } ], "resultType":"sum", //The overall result type of the entire roll "total":11 // The overall total of the entire roll (including all sub-groups) }
Roll Result Structure Example 2
An annotated structure for the result of /roll {1d6!!>5}>6
(showing exploding modifications and target successes):
{ "type":"V", "rolls": [ { "type":"G", "rolls": [ [ { "type":"R", "dice":1, "sides":6, "mods": { //Modifications to the roll "compounding": { //"compounding" = "Compounding exploding (!!)" "comp":">=", //Comparison type "point":5 //Comparison point } }, "results": [ { "v":13 //Overall dice result. Note that since this is compounding exploding there is only one dice result. } ] } ] ], "mods": { "success": { "comp":">=", "point":6 } }, "resultType":"sum", "results": [ { "v":13 } ] } ], "resultType":"success", // In this case, the result is a count of successes "total":1 //Total number of successes }
Chat Event Example (Implementing Custom Roll Type)
on("chat:message", function(msg) { //This allows players to enter !sr <number> to roll a number of d6 dice with a target of 4. if(msg.type == "api" && msg.content.indexOf("!sr ") !== -1) { var numdice = msg.content.replace("!sr ", ""); sendChat(msg.who, "/roll " + numdice + "d6>4"); } });
[edit] sendChat(speakingAs, input [,callback [, options]] ) Asynchronous
You can use this function to send a chat message.
speakingAs
can be one of:
- Any string, in which case that will be used as the name of the person who sent the message. E.g.
"Riley"
- A player's ID, formatted as
"player|-Abc123"
where-Abc123
is the ID of the player. If you do this it will automatically use the avatar and name of the player. - A character's ID, formatted as
"character|-Abc123"
. If you do this it will automatically use the avatar and name of the Character.
input
should be any valid expression just like the ones used in the Roll20 App. You enter text to send a basic message, or use slash-commands such as /roll
, /em
, /w
, etc. In addition:
- You can use Character#Attributes with the format
@{CharacterName|AttributeName}
. - You can use Character#Abilities with the format:
%{CharacterName|AbilityName}
. - You cannot use macros.
- You can use the "/direct <msg>" command to send a message without any processing (e.g. autolinking of URLs), and you can use the following HTML tags in the message:
<code><span><div><label><a><br><br /><p><b><i><del><strike><u><img><blockquote><mark><cite><small><ul><ol><li><hr><dl><dt><dd><sup><sub><big>
<pre><figure><figcaption><strong><em><table><tr><td><th><tbody><thead><tfoot><h1><h2><h3><h4><h5><h6>
- You can use a whitelisted set of inline CSS styles. The following tables list the full set of allowed properties and values:
Category | Description | Examples |
---|---|---|
Colors | Accepted format for colors is any of the following:
|
color: rgb(10,255,10) color: rgba(50%,50%,50%,0%) color: #aa99cc color: aliceblue |
Quantity | A positive number - integer or float. Must start with a digit, but can be suffixed with non-number word characters like rem/px/pt | border-radius: 5px font-size: 5.5rem |
Negative Quantity | The same as Quantity, but with a leading "-". No whitespace is allowed between the negative sign and the digits. | margin-left: -5px |
URL | Accepts a web URL using http:// or https:// - the resulting URL will be sanitized run through imgsrv.roll20.net | background: url(https://app.roll20.net/v2/images/roll20-logo.png) |
String Content | Rarely used, this allows most word characters through in the value. Still sanitized to remove any control characters, though. Strips any apostrophes and quotes from the ends and wraps the result in "quotations" | font: this font doesnt exist (passes the sanitizer but doesn't achieve anything) |
Z-Index | Any integer containing 1 to 7 digits. Only used for the z-index property itself | z-index: 1234567 |
CSS Property | Allowed Values |
---|---|
azimuth | Quantity Negative Quantity Literals: behind, center-left, center-right, far-left, far-right, left-side, leftwards, right-side, rightwards, left, right, center, inherit |
background | Colors Quantity Negative Quantity URL Literals: border-box, contain, content-box, cover, padding-box, no-repeat, repeat-x, repeat-y, round, space, bottom, top, left, right, ",", "/", auto, center, fixed, inherit, local, none, repeat, scroll, transparent |
background-size | Colors Quantity Negative Quantity URL Literals: border-box, contain, content-box, cover, padding-box, no-repeat, repeat-x, repeat-y, round, space, bottom, top, left, right, ",", "/", auto, center, fixed, inherit, local, none, repeat, scroll, transparent |
background-attachment | Literals: ",", fixed, local, scroll |
background-color | Colors Literals: inherit, transparent |
background-image | URL Literals: ",", none |
background-position | Quantity Negative Quantity Literals: bottom, top, left, right, ",", center |
background-repeat | Literals: no-repeat, repeat-x, repeat-y, round, space, ",", repeat |
border | Colors Quantity Negative Quantity Literals: dashed, dotted, double, groove, outset, ridge, solid, thick, thin, hidden, inherit, inset, medium, none, transparent |
border-bottom | Colors Quantity Negative Quantity Literals: dashed, dotted, double, groove, outset, ridge, solid, thick, thin, hidden, inherit, inset, medium, none, transparent |
border-bottom-color | Colors Literals: inherit, transparent |
border-bottom-left-radius | Quantity Negative Quantity |
border-bottom-right-radius | Quantity Negative Quantity |
border-bottom-style | Literals: dashed, dotted, double, groove, outset, ridge, solid, hidden, inherit, inset, none |
border-bottom-width | Quantity Negative Quantity Literals: thick, thin, inherit, medium |
border-collapse | Literals: collapse, inherit, separate |
border-color | Colors Literals: inherit, transparent |
border-left | Colors Quantity Negative Quantity Literals: dashed, dotted, double, groove, outset, ridge, solid, thick, thin, hidden, inherit, inset, medium, none, transparent |
border-left-color | Colors Literals: inherit, transparent |
border-left-style | Literals: dashed, dotted, double, groove, outset, ridge, solid, hidden, inherit, inset, none |
border-left-width | Quantity Negative Quantity Literals: thick, thin, inherit, medium |
border-radius | Quantity Negative Quantity Literals: "/" |
border-right | Colors Quantity Negative Quantity Literals: dashed, dotted, double, groove, outset, ridge, solid, thick, thin, hidden, inherit, inset, medium, none, transparent |
border-right-color | Colors Literals: inherit, transparent |
border-right-style | Literals: dashed, dotted, double, groove, outset, ridge, solid, hidden, inherit, inset, none |
border-right-width | Quantity Negative Quantity Literals: thick, thin, inherit, medium |
border-spacing | Quantity Negative Quantity Literals: inherit |
border-style | Literals: dashed, dotted, double, groove, outset, ridge, solid, hidden, inherit, inset, none |
border-top | Colors Quantity Negative Quantity Literals: dashed, dotted, double, groove, outset, ridge, solid, thick, thin, hidden, inherit, inset, medium, none, transparent |
border-top-color | Colors Literals: inherit, transparent |
border-top-left-radius | Quantity Negative Quantity |
border-top-right-radius | Quantity Negative Quantity |
border-top-style | Literals: dashed, dotted, double, groove, outset, ridge, solid, hidden, inherit, inset, none |
border-top-width | Quantity Negative Quantity Literals: thick, thin, inherit, medium |
border-width | Quantity Negative Quantity Literals: thick, thin, inherit, medium |
bottom | Quantity Negative Quantity Literals: auto, inherit |
box-shadow | Colors Quantity Negative Quantity Literals: ",", inset, none |
caption-side | Literals: bottom, top, inherit |
clear | Literals: left, right, both, inherit, none |
clip | Literals: auto, inherit |
color | Colors Literals: inherit |
content | String Content Literals: none, normal |
counter-increment | Quantity Negative Quantity Literals: inherit, none |
counter-reset | Quantity Negative Quantity Literals: inherit, none |
cue | URL Literals: inherit, none |
cue-after | URL Literals: inherit, none |
cue-before | URL Literals: inherit, none |
cursor | URL Literals: all-scroll, col-resize, crosshair, default, e-resize, hand, help, move, n-resize, ne-resize, no-drop, not-allowed, nw-resize, pointer, progress, row-resize, s-resize, se-resize, sw-resize, text, vertical-text, w-resize, wait, ",", auto, inherit |
direction | Literals: ltr, rtl, inherit |
display | Literals: -moz-inline-box, -moz-inline-stack, block, inline, inline-block, inline-table, list-item, run-in, table, table-caption, table-cell, table-column, table-column-group, table-footer-group, table-header-group, table-row, table-row-group, inherit, none |
elevation | Quantity Negative Quantity Literals: above, below, higher, level, lower, inherit |
empty-cells | Literals: hide, show, inherit |
filter | - |
float | Literals: left, right, inherit, none |
font | Quantity String Content Literals: 100, 200, 300, 400, 500, 600, 700, 800, 900, bold, bolder, lighter, large, larger, small, smaller, x-large, x-small, xx-large, xx-small, caption, icon, menu, message-box, small-caption, status-bar, cursive, fantasy, monospace, sans-serif, serif, italic, oblique, ",", "/", inherit, medium, normal, small-caps |
font-family | String Content Literals: cursive, fantasy, monospace, sans-serif, serif, ",", inherit |
font-size | Quantity Literals: large, larger, small, smaller, x-large, x-small, xx-large, xx-small, inherit, medium |
font-stretch | Literals: condensed, expanded, extra-condensed, extra-expanded, narrower, semi-condensed, semi-expanded, ultra-condensed, ultra-expanded, wider, normal |
font-style | Literals: italic, oblique, inherit, normal |
font-variant | Literals: inherit, normal, small-caps |
font-weight | Literals: 100, 200, 300, 400, 500, 600, 700, 800, 900, bold, bolder, lighter, inherit, normal |
height | Quantity Negative Quantity Literals: auto, inherit |
left | Quantity Negative Quantity Literals: auto, inherit |
letter-spacing | Quantity Negative Quantity Literals: inherit, normal |
line-height | Quantity Literals: inherit, normal |
list-style | URL Literals: armenian, circle, decimal, decimal-leading-zero, disc, georgian, lower-alpha, lower-greek, lower-latin, lower-roman, square, upper-alpha, upper-latin, upper-roman, inside, outside, inherit, none |
list-style-image | URL Literals: inherit, none |
list-style-position | Literals: inside, outside, inherit |
list-style-type | Literals: armenian, circle, decimal, decimal-leading-zero, disc, georgian, lower-alpha, lower-greek, lower-latin, lower-roman, square, upper-alpha, upper-latin, upper-roman, inherit, none |
margin | Quantity Negative Quantity Literals: auto, inherit |
margin-bottom | Quantity Negative Quantity Literals: auto, inherit |
margin-left | Quantity Negative Quantity Literals: auto, inherit |
margin-right | Quantity Negative Quantity Literals: auto, inherit |
margin-top | Quantity Negative Quantity Literals: auto, inherit |
max-height | Quantity Literals: auto, inherit, none |
max-width | Quantity Literals: auto, inherit, none |
min-height | Quantity Literals: auto, inherit |
min-width | Quantity Literals: auto, inherit |
opacity | Quantity Literals: inherit |
outline | Colors Quantity Negative Quantity Literals: dashed, dotted, double, groove, outset, ridge, solid, thick, thin, hidden, inherit, inset, invert, medium, none |
outline-color | Colors Literals: inherit, invert |
outline-style | Literals: dashed, dotted, double, groove, outset, ridge, solid, hidden, inherit, inset, none |
outline-width | Quantity Negative Quantity Literals: thick, thin, inherit, medium |
overflow | Literals: auto, hidden, inherit, scroll, visible |
overflow-x | Literals: no-content, no-display, auto, hidden, scroll, visible |
overflow-y | Literals: no-content, no-display, auto, hidden, scroll, visible |
padding | Quantity Literals: inherit |
padding-bottom | Quantity Literals: inherit |
padding-left | Quantity Literals: inherit |
padding-right | Quantity Literals: inherit |
padding-top | Quantity Literals: inherit |
page-break-after | Literals: left, right, always, auto, avoid, inherit |
page-break-before | Literals: left, right, always, auto, avoid, inherit |
page-break-inside | Literals: auto, avoid, inherit |
pause | Quantity Negative Quantity Literals: inherit |
pause-after | Quantity Negative Quantity Literals: inherit |
pause-before | Quantity Negative Quantity Literals: inherit |
pitch | Quantity Negative Quantity Literals: high, low, x-high, x-low, inherit, medium |
pitch-range | Quantity Negative Quantity Literals: inherit |
play-during | URL Literals: auto, inherit, mix, none, repeat |
position | Literals: absolute, relative, static, inherit |
quotes | String Content Literals: inherit, none |
richness | Quantity Negative Quantity Literals: inherit |
right | Quantity Negative Quantity Literals: auto, inherit |
speak | Literals: inherit, none, normal, spell-out |
speak-header | Literals: always, inherit, once |
speak-numeral | Literals: continuous, digits, inherit |
speak-punctuation | Literals: code, inherit, none |
speech-rate | Quantity Negative Quantity Literals: fast, faster, slow, slower, x-fast, x-slow, inherit, medium |
stress | Quantity Negative Quantity Literals: inherit |
table-layout | Literals: auto, fixed, inherit |
text-align | Literals: left, right, center, inherit, justify |
text-decoration | Literals: blink, line-through, overline, underline, inherit, none |
text-indent | Quantity Negative Quantity Literals: inherit |
text-overflow | Literals: clip, ellipsis |
text-shadow | Colors Quantity Negative Quantity Literals: ",", inset, none |
text-transform | Literals: capitalize, lowercase, uppercase, inherit, none |
text-wrap | Literals: suppress, unrestricted, none, normal |
top | Quantity Negative Quantity Literals: auto, inherit |
unicode-bidi | Literals: bidi-override, embed, inherit, normal |
vertical-align | Quantity Negative Quantity Literals: baseline, middle, sub, super, text-bottom, text-top, bottom, top, inherit |
visibility | Literals: collapse, hidden, inherit, visible |
voice-family | String Content Literals: child, female, male, ",", inherit |
volume | Quantity Literals: loud, silent, soft, x-loud, x-soft, inherit, medium |
white-space | Literals: -moz-pre-wrap, -o-pre-wrap, -pre-wrap, nowrap, pre, pre-line, pre-wrap, inherit, normal |
width | Quantity Literals: auto, inherit |
word-spacing | Quantity Negative Quantity Literals: inherit, normal |
word-wrap | Literals: break-word, normal |
z-index | Quantity Negative Quantity Z-Index Literals: auto, inherit |
zoom | Quantity Literals: normal |
CSS Property | Allowed Values |
---|---|
-moz-border-radius | Quantity Negative Quantity Literals: "/" |
-moz-border-radius-bottomleft | Quantity Negative Quantity |
-moz-border-radius-bottomright | Quantity Negative Quantity |
-moz-border-radius-topleft | Quantity Negative Quantity |
-moz-border-radius-topright | Quantity Negative Quantity |
-moz-box-shadow | Colors Quantity Negative Quantity Literals: ",", inset, none |
-moz-opacity | Quantity Literals: inherit |
-moz-outline | Colors Quantity Negative Quantity Literals: dashed, dotted, double, groove, outset, ridge, solid, thick, thin, hidden, inherit, inset, invert, medium, none |
-moz-outline-color | Colors Literals: inherit, invert |
-moz-outline-style | Literals: dashed, dotted, double, groove, outset, ridge, solid, hidden, inherit, inset, none |
-moz-outline-width | Quantity Negative Quantity Literals: thick, thin, inherit, medium |
-o-text-overflow | Literals: clip, ellipsis |
-webkit-border-bottom-left-radius | Quantity Negative Quantity |
-webkit-border-bottom-right-radius | Quantity Negative Quantity |
-webkit-border-radius | Quantity Negative Quantity Literals: "/" |
-webkit-border-radius-bottom-left | Quantity Negative Quantity |
-webkit-border-radius-bottom-right | Quantity Negative Quantity |
-webkit-border-radius-top-left | Quantity Negative Quantity |
-webkit-border-radius-top-right | Quantity Negative Quantity |
-webkit-border-top-left-radius | Quantity Negative Quantity |
-webkit-border-top-right-radius | Quantity Negative Quantity |
-webkit-box-shadow | Colors Quantity Negative Quantity Literals: ",", inset, none |
callback
is an optional third parameter consisting of a callback function which will be passed the results of the sendChat()
call instead of sending the commands to the game. Using sendChat()
in this way is asynchronous. The results of the sendChat()
command will be an ARRAY of operations, and each individual object will be just like an object you receive during a chat:message
event (see above).
You can use this, for example, to perform a roll using the Roll20 roll engine, then get the results of the roll immediately. You could then perform additional modifications to the roll before sending it to the players in the game.
sendChat("Riley", "/roll 1d20+4", function(ops) { // ops will be an ARRAY of command results. var rollresult = ops[0]; //Now do something with rollresult, just like you would during a chat:message event... });
options
is an optional fourth parameter to set options for how the message is handled. Options are specified as a javascript object with who's properties are the names of the options to set and whose values are the settings for them, generally true
as they default to false.
Available options:
-
noarchive
-- set this to true to prevent the message from being stored in the chat log. This is particularly useful for output that is not part of the story, such as API Button menus and state information.
-
use3d
-- You can now generate 3D Dice rolls using the sendChat() function. The syntax is simply:sendChat("Name", "Rolling [[3d6]]", null, {use3d: true});
If you pass a player ID to the name parameter, such assendChat("player|-ABC123",...)
the player's color will be used for the dice. Otherwise a default white color will be used.
Note: Clients can only show the result of one 3D roll at a time, so making a bunch of separate 3D rolls in a row is not useful. Also note that using 3D rolls does place a bit more strain on the QuantumRoll server, so use your judgement and don't perform 100 3D rolls in the space of a second. Use 3D rolls when the roll will "matter" to the player and make an impact on the game. Warning: The use3d parameter does not seem to be working as of July 2021, c.f.: https://app.roll20.net/forum/post/9017606/slug%7D.
If you want to adjust these options but do not want to use a callback
parameter (third parameter--see above), you can simply pass null
in it's place:
sendChat("Status", "All players are logged in.", null, {noarchive:true} );
[edit] API Command Buttons
Main Page: Complete Guide to Macros & Rolls
You can take advantage of the q Text Chat-formatting (in both your API-generated messages and those generated by macros and abilities) to create "API command buttons" in the chat.
To do so using Markdown formatting:
[Attack Roll](!attackroll)
The text in between the brackets will show up in the button, and part in the parentheses is the command to be executed. You can include anything in a normal roll (macros, abilities, queries, etc.), but keep in mind that the command itself will be executed by the player who clicks on it. For example, don't include @{Character|AC}
if everyone who can see the message can't access that character. Instead, include the actual value as it existed when you sent the command by filling it in yourself before you send the chat message. These buttons will work in all message types, general messages, whispers, gmwhispers, etc.
Note that if you use /direct to send a message, we won't do any Markdown parsing on it, so you need to include your own <a> tags. Here's an example of that:
<a href="!attackroll">Attack Roll</a>
[edit] Entering API Buttons In Chat
You can also type Markdown syntax API buttons into chat for others to use. Because they will be interpreted by the chat parser, if you want attributes, queries and rolls to be expanded when the button is clicked, you must enter parts of the command with a special syntax (HTML Entities):
Character | Replacement |
---|---|
% | % |
) | ) |
? | ? |
@ | @ |
[ | [ or [ |
] | ] or ] |
This sample button uses some of them:
[Attack Roll](!attackroll @{target|token_id} [[1d6+?{Bonus|0}]])
You can actually use the API Buttons to call Macros or Abilities.
Character | Replacement |
---|---|
<carriage return> | |
To do so, you simply begin the command portion with the special code !
then add the macro call with #
or the ability call with %
(%
):
[Macro](! #MacroName)
[Ability](! %{CharName|AbilityName})
Note: At this time, reopening a Macro saved under the l Collections-tab of the Sidebar causes HTML entities within to be reverted; if the Macro is then saved, so are those reversions. This behavior is not present within Abilities or Ability Command Buttons.
For Ability Command Buttons, if the Ability that creates the button and the Ability it references are both on the same sheet, the syntax is very simple:
[Ability](~AbilityName)