Difference between revisions of "Script:ScriptCards"
From Roll20 Wiki
(→Set Parameter (--#)) |
(→Built-In Function (--~)) |
||
Line 1,384: | Line 1,384: | ||
|- | |- | ||
| string || totitlecase || string || stringVariable || Converts the passed string to title case (capitlaizes the first letter of each word) and assigns to the passed variable name. | | string || totitlecase || string || stringVariable || Converts the passed string to title case (capitlaizes the first letter of each word) and assigns to the passed variable name. | ||
+ | |- | ||
+ | | string || onlynumbers || string || stringVariable || Returns only the number values from a string, preserving a leading - sign if it is the first non-whitespace character in the string. | ||
+ | |- | ||
+ | | string || nonumbers || string || stringVariable || Returns a string with all numeric characters (0 thru 9) removed. | ||
|- | |- | ||
| stateitem || write || stateitem;write;variableType || None || Writes the variable specified in the '''tag''' to persistent storage. Specify either '''rollvariable''' or '''stringvariable''' for '''variableType'''. One of each type can be stored in persistent storage at a time. | | stateitem || write || stateitem;write;variableType || None || Writes the variable specified in the '''tag''' to persistent storage. Specify either '''rollvariable''' or '''stringvariable''' for '''variableType'''. One of each type can be stored in persistent storage at a time. |
Revision as of 11:03, 31 January 2023
Page Updated: 2023-01-31 |
Version: 1.6.4
Last Modified: 2022-02-27
Code: ScriptCards
Dependencies: None
Conflicts: None
Introduction
What is ScriptCards
The ScriptCards Mod (API Script) implements a feature-rich script interpreter for writing programs inside macros and abilities withing Roll20. ScriptCards is not tied to any specific game system or character sheet. The language supports many traditional programming features and a number of features specifically geared towards Roll20, including:
- Settings – More than 70 modifiable settings to control the appearance and behavior of executing scripts (fonts, colors, image backgrounds, and many, many more)
- Variables – String variables and Roll variables. Roll variables can be set using a built-in roll parser that can reference other variables and values when creating Rolls, as well as a number of other math related modifiers.
- Arrays – Arrays can be defined directly in your scripts or sourced from game information (ie, status markers on tokens, etc.)
- For…Next Loops – Including the ability to break out of the current loop execution or exit the loop entirely. Loops support start, end, and step values.
- Branching – Both direct (goto-style) branching and function calling (gosub branching) are supported. Gosub nesting is supported, and parameters can be passed to a gosub branch.
- Conditionals – If/Then/Else style conditionals (including code block support) and Switch/Case style conditionals.
- Built-in Functions – A library of built-in functions for array manipulation, math, string manipulation, and system interaction with Roll20 (turnorder, date/time)
- Calling other Mod Scripts – A syntax for building Mod calls to run asynchronously as part of a ScriptCard execution.
- Object Property access and Manipulation – Access and update the properties of Roll20 objects such as tokens, characters, graphics, etc. Built-in property modification is immediately available to the remained of the executing script.
- Nested, Run-Time Referencing – Because ScriptCards lines are processed by an interpreter when the line executes, any portion of the line can be replaced by a variable reference, and any type of reference can be nested. Evaluation works from the inside out, so the final reference can be made up of subreferences.
- Code Libraries – Roll20 Handouts can be used to store common code functions that you wish to make available to your other scripts.
- Infinite Loop Protection – ScriptCards maintains an internal execution count to prevent crashing the Roll20 sandbox if your script enters an infinite loop.
- New in ScriptCards 2.0 – Triggers – ScriptCards can be configured to respond to various events that take place in the Roll20 VTT environment, such as tokens taking damage, turn order updates, and more.
Current OneClick Version: 2.2.0
Current Development Version: 2.2.4c
Note: The documentation below is in the process of being revised and updated with the release of version 2.2.4c
Critically Important: ScriptCards does not parse inline rolls. ScriptCards includes its own built-in dice roll parser to allow for the use of variables inside dice rolls. The final numeric value of an inline roll can be used in a ScriptCard, but only as a text substitution value, so inline rolls can't reference the value of ScriptCards variables.
Links
- ScriptCards thread on the Roll20 Mod forum(Forum)
- Changelog
- ScriptCards_API - GitHub repository for source before the one-click version is updated.
- ScriptCards Samples - Branch of the GitHub repo that contains sample scripts.
- Discord Channel
- ScriptCards Intro 45min, Jan 2021
- ScriptCards Magic Missile Deep Dive 39min, Feb 2021
ScriptCards 2.0 - Now with Triggers
The newest version of ScriptCards (currently in development on the GitHub repo and tagged as experimental) supports a feature called "ScriptCards Triggers", which allows you to respond to in-game events by running macros (ScriptCards scripts or otherwise) when tokens, pages, attributes, etc. change in your game. This wiki documentation is in the process of being updated to include information for post 1.7.7 updates, including information for 2.0. While these features are available now from the experimental section of the repo, they will not be available in OneClick installs until the newest version has been pushed to Roll20.
Is ScriptCards Related to PowerCards?
I (Kurt J.) have been maintaining and updating PowerCards for a couple of years now, and ScriptCards isn't an effort to supplant PowerCards, but rather represents my effort to address some of the most common issues that PowerCards users run into because of the intrinsic nature of the way PowerCards was conceived and developed over time. ScriptCards is more of a follow-up to PowerCards. Perhaps the most frequent question asked in the PowerCards thread on the forum is something along the lines of “how do I use the result of THIS roll in the roll I make two lines later?” Unfortunately, due to the architecture of PowerCards, this isn’t possible.
Besides this issue, there are various elements of a PowerCards macro that can’t support certain features. For example, you can’t set most card-wide settings (name
, leftsub
, rightsub
) dependent upon the results of a dice roll, and while I’ve implemented a simple “skip forward” mechanism in PowerCards to allow for some flow control, true branching (forward and backwards) is not possible due to the way cards are processed. While it might be possible to rewrite some of the core of PowerCards to allow for implementation of (some) of these features, the result would be a very different script that would not be backwards compatible with the host of users currently using PowerCards in their games.
Instead, I have taken the approach of writing a completely new script from the ground up. There is very little (if any) of the original PowerCards code included in ScriptCards because I am fundamentally changing the way the macro is processed. Note that this isn’t a slight against the original author of PowerCards (Sky). The script has been widely used for years now, and is a testament to the flexibility of the original code that I was able to add so many features over the past two years.
By implementing ScriptCards as a new, separate script, those using PowerCards as it currently exists can continue to do so without interruption, while those interested in the functionality of ScriptCards can make use of its updated feature set. The two script (PowerCards and ScriptCards) can happily coexist in the same game, and do not interfere with each other in any way.
Check the What to Know if you are Coming from PowerCards-section for a comparison table between the two scripts.
What is a ScriptCard Script
A ScriptCard script is text written into the q Text Chat (either typed directly, pasted, or run via a macro/character ability) that will be interepreted and executed by the ScriptCards language processor. In most cases, the result of the script will produce output displayed as an HTML formatted "card" in the chat window. A ScriptCard script is composed of an API command: !scriptcard {{ }}
enclosing any number of lines that determine what actions the script will take and the output that will be added to the card. At it simplest, the following macro:
!scriptcard {{ }}
Will produce just a title card that displays “ScriptCards” as the name:
Of course, this is just the bare essential macro and isn’t very useful. In order to produce output that is helpful for playing a Roll20 game, we need to include lines between the {{
and }}
that direct the API script as to what it should do.
Structure of a ScriptCard Script
The body of a ScriptCard Script contains one or more statement lines, which, as a general rule, are interpreted as they are executed and run sequentially from top to bottom. There are exceptions to this general functionality, including the ability to branch to other parts of the code, call subroutines, and terminate execution. There are also special constructs utilized by Reentrant Scripts, that allow execution to begin at locations other than the top of the script. These exceptions will be covered later in this documentation.
A ScriptCard line begins with two dashes, followed by a statement identifier character that lets the interpreter know what type of line it is. There are many different types of statements, and the bulk if this Wiki entry is dedicated to covering the use and function of each one.
After the line type identifier, an optional bit of text referred to as the line's Tag is supplied. This name is essentially free-form and CAN be omitted in the case of some line types. Also note that if you are used to using PowerCards, Tags in ScriptCards do not need to be unique.
Following the Tag is a vertical bar, and then the Content portion of the line. Again, each type of line might interpret this content differently, and in the case of some statement types it is optional.
Example:
--#title|Longsword Attack
In this example:
- # is the statement identifier character, indicating that this line will be a "settings" statement.
- title is the statement Tag. For the "#" statement type, the Tag indicates what setting we will be updating.
- | separates the Tag from the Content
- Longsword Attack is the Content portion of the statement. In this case, it indicates what will be placed in the "title" setting.
Notes
ScriptCards lines are delimited by the --
sequence. This means that whitespace before/after a line is ignored by the interpreter. The following two scripts are identical as far as the interpreter is concerned:
!script {{ --#title|Stealth Check --=Roll|1d20 + @{selected|stealth} --+|@{selected|token_name} attempts to move undetected... --+Stealth|@{selected|token_name} rolled a [$Roll] }}
!script{{--#title|Stealth Check--=Roll|1d20 + @{selected|stealth}--+|@{selected|token_name} attempts to move undetected...--+Stealth|@{selected|token_name} rolled a [$Roll]}}
Statement Types Quickreference
The table below lists each of the statement identifier types available in the ScriptCards language. Each entry also lists what the Tag is used for (if at all) and the format the Content is expected to be in along with usage notes.
Identifier Statement Type Tag Content Notes --/ Comment unused unused The --/
sequence is used to add comments to a script. No processing will take place on a --/ line, so the tag and comment can be freely used to add notes to your code.--\ Console Log unused Log Text ) to the API console log. --# Set Parameter Parameter name Desired parameter value Parameters generally control the behavior of large segments of the output card. Things like the Title of the card, the colors of the header and rows, etc. There are also parameters that control how various features of the card behave (like "usehollowdice"). --+ Direct Output Free Text - Is output in bold at start of the line. Output in normal text after Tag Direct Output statements are what creates row sections on the output card. A script without any direct output sections will end up looking similar to the sample at the start of this wiki (the !script {{ }} script) because all other statement types do not create output lines. --= Assign Roll Variable Variable Name Roll Equation (or text) to assign Roll/Numeric variables are assigned with this command. The content will be processed as a dice roll, and various properties will be set along with the numeric results. --& Assign String Variable Variable name Content to store in the string variable. Roll Variables and String Variables are completely separate entities, and can technically share names, but this would likely lead to confusion and should be avoided. --@ API Call API ! Command API call parameters (replace -- with _) Other Roll20 API scripts can be called using this command. The Tag is the trigger command for the API script (i.e., !token-mod, or !setattr, etc.) --: Branch Label Label Name Unused (Comments if desired) Branch labels are the destination for branch and procedure call statement types. The content portion of the statement is unused, though it is recommended to list parameter information here if you are writing a procedure that accepts passed parameters --^ Branch To Label name to branch to Unused (Comments if desired) An unconditional branch to a label (--:). Execution of the script will jump to the line after the named label. --> Call Procedure Label name to call Procedure parameter list semicolon (;) separated An unconditional procedure call. Execution will jump to the line after the named label, and a return statement (--<) will return execution to the line after the procedure call --< Return from Sub Unused Unused (Comments if desired) The return statement returns execution to the most recent procedure call line. Note that the vertical bar is required for the statement to be complete. --? Conditional Branch Condition to be evaluated True Branch Label|False Branch Label The condition will be evaluated and execution will jump to one of the two indicated branches (or simply continue to the next line if only a True branch is specified and the result is False). You can make the branch a procedure call by prefixing the label with a > symbol. In this case, you can included a semicolon separated list of parameters. --s Store to Persistent Storage "settings", "rollvariables", or "stringvariables" Name of the data set to store (see save/load section below) This statement type (and the --l statement) still function, but it is recommended to use the storage mechanism in the --~ command instead. --l Load from Persistent Storage "settings", "rollvariables", or "stringvariables" Name of the data set to store (see save/load section below) This statement type (and the --s statement) still function, but it is recommended to use the storage mechanism in the --~ command instead. --v Create Visual Effect "token", "betweentokens", or "point" Tokens and parameters for generating the effect Visual effects are played on the page the token is on. "point" effects require Version 1.2.8+ --a Play Audio Track Unused Jukebox track name (case sensitive) Plays an audio track by name from the Roll20 jukebox. Requires v1.5.2+ --e Echo to Chat Name to send chat command as Chat message to send Variable substitution takes place on the tag and content. --R Retrieve Repeating Section Row information "find", "first", or "next" Parameters for retrieving row information. See Referencing below Working with repeating section information on character sheets is possible without tracking row indexes ($0, $1, etc.) by using the --R statements. --~ Assign a variable to the result of a built-in function Variable Name Parameters for function call ScriptCards includes a number of built-in functions for things like measuring distance, manipulating strings, etc. The type of variable that gets set (Roll or String) is dependent upon the function that is being called. --c Case Statement Test Value Vertical bar separated list of cases, with the match:branchlabel format. Branch labels can be procedure calls by prefixing them with ">", and can contain parameters. --i Information Request User Prompt;Button Caption InfoType;VariableName;ParameterText See full documentation below. --d Data Statement ! for data definition or StringVar for data read For definition lines, a semicolon separated list of data elements. Unused to read lines. Similar to BASIC read/data statements. --d! defines string data elements anywhere in your code. --dvarName reads the next data element into varName. --% For...Next Loop Loop Counter for "For", empty for "Next" For "For", Start;End;Step, empty for Next See For...Next Loop documentation below. Allows you to create loops that will run a specified number of times with a loop counter. --* GM Output Free Text - Is output in bold at start of the line. Output in normal text after Tag GM Output statements are whispered to the GM as a separate card after the output of the main card is completed. Their use is identical to the Direct Output statement (--+). If there are no GM Output statements in a card, no GM card will be whispered. --! Object Modification <objectType>:<objectId> setting:value|setting:value... Set properties of tokens/characters or character attributes (v1.5.0+ required) --X Exit Script none none End script processing and exit the script.
ScriptCard Statement Type Details
The sections below detail the individual statement types supported by ScriptCards
Comment (--/)
A --/
statement is ignored by the ScriptCards parser. You can use this type of statement to add comments and informational text to your script.
--/|[Comment Text]
Example:
!script {{ --/|Script Name : Fireball --/|Purpose : Allow the player to cast a fireball and blow stuff up! . . . }}
Console Log (--\)
A --\
statement will ignore the **tag** portion of the statement and output the **content** portion of the statement to the API console log, including variable substitution.
--\|[Log Text]
Example:
!script {{ --\|The value of Roll is [$Roll] }}
Set Parameter (--#)
A --#
statement sets parameters used by ScriptCards when the card output is built. These include things like the title of the card, the background colors used for various portions of the card, the content of the left and right subtitle blocks, the tokens displayed in the emote (if any), the emote text, etc. A full list of these setting values is included below.
--#<ParameterName>|[Parameter Value]
For settings statements, the Tag determines the setting that will be updated, while the Content determines the value that will be stored in that setting.
For global settings, if the same setting is set multiple times in a script, the MOST RECENTLY EXECUTED setting will be what is used when the card output is built. Most settings are "Per-Line", meaning they will only impact output lines generated after the setting is made, and can thus be changed with every line if desired.
Examples:
--#title|Magic Missile --#leftsub|Level 1 Spell --#rightsub|Force Damage
The three examples above set the “title”, “leftsub”, and “rightsub” values for the card to the content value for the line.
Content portions can include roll variables (see --=
lines below) and can be used multiple times in a macro. The last execution of a setting line will be the one used when the card output is generated.
Settings Lines do not produce output lines on the card.
The following link is an image that shows the various sections of a ScriptCard:
https://cdn.discordapp.com/attachments/1034740409580130358/1066948467437617172/SC_Card_Illustrated.png
The following settings are available (note that parameter names are not case sensitive) and are grouped by the section they apply to:
Overall/ Admin Settings Name Effect/Use Default Value Type hideCard If set to any non-default value, the entire card output will be suppressed 0 Global whisper Comma separated list of who to whisper the output to. Use "gm" for GMs and "self" for the sender none Global showFromForNonWhispers If set to a non-zero value, will include the sender on cards that aren't whispered 0 Global reentrant Used to name a script for rentrant button use 0 Global parameterDelimiter Specify the character sequence used to separate parameters in various calls (defaults is semi-colon (;)) (1.6.7+) none Per-Line executionLimit Maximum number of script lines the interpreter will try to execute. This prevents "infinite loop" sandbox crashes 40000 Global deferralCharacter Changes the meta script deferral sequence to the specified value ^ Per-Line debug If set to a non-zero value, will output lots (and LOTS) of information to the API console log about the running script. Useful for troubleshooting. 0 Per-Line timezone IANA Specifier for the local time zone, used in system/date functions America/
New_YorkPer-Line
Selection Settings Name Effect/Use Default Value Type activePage If set to a page ID, will be used for [*P:] attribute references. The "playerpage" string can be used to retrieve the current player ribbon page. empty Per-Line sourceToken Token ID of the Source character. Will be displayed in the left portion of the emote area if specified, and will be used for referencing attributes. None Per-Line targetToken Token ID of the Target character. Will be displayed in the right portion of the emote area if specified, and will be used for referencing attributes. None Per-Line
Title Settings Name Effect/Use Default Value Type hideTitleCard If set to any non-default value, the top portion of the card (title and subtitle area) will not be included on the output 0 Global titleCardBackground A hex color code representing the background color of the title area. #1c6ea4 Global titlecardBackgroundImage Specify an image (content for a CSS background-image tag) for the title card area
Example: --#titlecardbackground|url('https://s3.amazonaws.com/files.d20.io/images/248538196/c9xft1A2jWNqOkBsxQwyLQ/max.jpg?1633278017'); background-size: 100% 100%; background-repeat: no-repeat;none Global titleFontLineHeight Line spacing on the title area 1.2em Global titleFontFace Name of the font used on the title area Contrail One Global titleFontSize Size of the title font 1.2em Global titleFontColor Color of the text on the card title #FFFFFF Global titleCardBottomBorder Border CSS specifier for the bottom of the title card area 2px solid #444444; Global titleCardGradient If set to non-zero value, will place a vertical gradient on the title card area 0 Global title Text displayed in the title area of the card ScriptCards Global
Subtitle Settings Name Effect/Use Default Value Type subtitleFontFace Name of the font used on the subtitle sections Tahoma Global subtitleFontSize Size of the subtitle font 13px Global subtitleFontColor Color of the text in the subtitle areas #FFFFFF Global subtitleSeparator The character(s) that will be placed between leftsub and rightsub ♦ Global leftSub Subtitle text. Will be centered if rightsub isn’t specified, otherwise will be offset to the left with a separator between leftsub and rightsub. None (Empty) Global rightSub Subtitle text. Will be centered if leftsub isn’t specified, otherwise will be offset to the right with a separator between leftsub and rightsub. None (Empty) Global
Emote Settings Name Effect/Use Default Value Type emoteState If set to anything other than "visible", the emote portion of the card will not be displayed visible Global emoteBackground Background color of the emote area #f5f5ba Global emoteFontWeight Font weight for the font in the emote area bold Global emoteFont Name of the font used in emote area (above the title of the output card) font-family: Georgia, serif; font-weight: bold; Global emoteFontSize Size of the font used in the emote area 14px Global emoteFontColor Color of the font in the emote area None (Empty) Global emoteText Text to display in the emote portion of the card None (Empty) Global
Main Description Settings Name Effect/Use Default Value Type evenRowBackground Hex code for the background color for even rows #eeeeee Per-Line oddRowBackground Hex code for the background color for even rows #d0e4f5 Per-Line bodyBackgroundImage Specify an image (content for a CSS background-image tag) for the body area none Global evenRowBackgroundImage Specify an image (content for a CSS background-image tag) for the even card rows
Example: --#evenRowBackgroundImage|url('https://s3.amazonaws.com/files.d20.io/images/248538196/c9xft1A2jWNqOkBsxQwyLQ/max.jpg?1633278017'); background-size: 100% 100%; background-repeat: no-repeat;none Per-Line oddRowBackgroundImage Specify an image (content for a CSS background-image tag) for the odd card rows
Example: --#oddRowBackgroundImage|url('https://s3.amazonaws.com/files.d20.io/images/248538196/c9xft1A2jWNqOkBsxQwyLQ/max.jpg?1633278017'); background-size: 100% 100%; background-repeat: no-repeat;none Per-Line LineHeight Vertical size of each line on the output card normal Per-Line bodyFontFace Name of the font used in the card rows Helvetica Global bodyFontSize Size of the text in the card rows 14px Global evenRowFontColor Hex code for the text color for even rows #000000 Per-Line oddRowFontColor Hex code for the text color for odd rows #000000 Per-Line tableBGcolor Background color of the whole card. Normally not visible #EEEEEE Global tableBorder Color of the border that surrounds the whole card 2px solid #000000; Global tableBorderRadius CSS specifier for how rounded the borders of the output card are. Use "0px;" for square borders 6px; Global tableShadow CSS specifier for the drop shadow under the output card 5px 3px 3px 0px #aaa; Global
Dice Roll Settings Name Effect/Use Default Value Type rollHilightLineHeight Determines the height of the hilight box placed around roll results (1.4.2+) 1.0em Per-Line diceFontSize Size of the dice created with the [d4] [d6], etc. formatting markers 3.0em Per-Line diceFontColor Color of the dice created with the [d4] [d6], etc. formatting markers #1C6EA4 Per-Line rollHilightcolorboth Background box hilight color if both a 1 and a max on the die are rolled (1.4.4+) #8FA4D4 Per-Line rollHilightColorCrit Background box hilight color if the maximum number on the die was rolled (1.4.4+) #88CC88 Per-Line rollHilightColorFumble Background box hilight color if a 1 was rolled (1.4.4+) #FFAAAA Per-Line rollHilightColorNormal Background box hilight color if neither a 1 or a max on the die are rolled (1.4.4+) #FFFEA2 Per-Line noMinMaxHighlight If set to anything other than "0", rolls will not display crit/fumble/mixed highlight colors. 0 Per-Line noRollHighlight If set to anything other than "0", rolls will not be formatted (plain numbers) but will still get a tooltip with details 0 Per-Line allowPlainTextInRolls If set to a non-zero value, plain character text in rolls will be copied to the roll text 0 Per-Line disableInlineFormatting If set to a non-zero value, inline formatting (bold, italics, color, text alignment, etc.) will not be performed on --+ lines 0 Per-Line disableRollProcessing If set to a non-zero value, --= lines will not process dice rolls strings 0 Per-Line roundUp If set to a non-default value, integer division will round up instead of down 0 Per-Line useHollowDice If set to a non-zero value, the hollow/outline versions of the dice fonts will be used 0 Per-Line explodingonesandaces If set to 1, rerolls on exploding dice will be figured into the Ones and Aces properties of the roll 0 Per-Line
Button Settings Name Effect/Use Default Value Type buttonBackground Background color for buttons created with [button][/button] #1C6EA4 Per-Line buttonBackgroundImage A CSS specifier for a background image to use for buttons (i.e. url(...);)
Example: --#buttonBackgroundImage|url('https://s3.amazonaws.com/files.d20.io/images/248538196/c9xft1A2jWNqOkBsxQwyLQ/max.jpg?1633278017'); background-size: 100% 100%; background-repeat: no-repeat;empty Per-Line buttonFontSize Text size for captions on buttons created with [button][/button] x-small Per-Line buttonFontFace Font Family specifier for captions on buttons created with [button][/button] Tahoma Per-Line buttonTextColor Text color of labels on buttons created with [button][/button] #FFFFFF Per-Line buttonPadding Set the size of the padding area around buttons 5px Per-Line buttonBorderColor Border (outline) color for buttons created with [button][/button] #999999 Per-Line
As of ScriptCards 1.6.0, ten user settings (usersetting0
thru usersetting9
) are now available. These settings are not used by ScriptCards but are available for script author use. These settings are stored with setting set (--Ssettings
and --Lsettings
).
Setting Lines do not produce output lines on the card
Direct Output (--+)
A direct output line(--+
) that displays a line of content on the ScriptCard. It can be a simple line of text with a Tag/Content pair, or it can include Roll Variable references and inline formatting. The Tag can be blank (the |
is still required). If a tag is specified, it is output in bold at the beginning of the line followed by the content.
--+[Bolded Text Output]|[Text Output]
Examples of Direct Output lines:
--+Hello|World --+Attack|The monster rolls [$Attack] to hit! --+Damage|@{target|token_name} is hit for [$Damage] [#3333AA][b]frost[/b][/#] damage.
Direct Output lines support inline formatting, roll variable replacement, character attribute references, and procedure variables.
GM Output (--*)
A GM Output line--*
is identical to a direct output line(--+
), except that it will be sent on a separate card that is only visible to GMs.
--*[Bolded Text Output]|[Text Output]
Example:
--+PlayerLine|This line is shown on the public card --*GMLine|This line will only be shown to GMs, on a separate card.
Roll Variable Assignment (--=)
See the Variables section for more information on Roll Variables
In ScriptCards, when you want to roll dice you need to store the result of the roll into a Roll Variable. This is done by specifying the name of the Roll Variable as the Tag, and the roll text as the Content of the line.
--=<Roll Variable Name>|[Roll Component] [Roll Component] ...
All components of a roll equation should be separated with spaces.
Examples:
--=MissileDamage|1d4 + 1 --=Attack|1d20 + @{selected|strength_mod} [STR] + @{selected|pb} [PROF]
In these examples, the MissileDamage Roll Variable will be set to the result of rolling 1d4 and adding 1. The Attack Roll Variable will roll 1d20, add the selected character’s strength modifier and proficiency bonus (assuming D&D 5E) and store that value into the variable. Text enclosed in square brackets ([]) is considered "flavor text" and will be added to the result text but does not impact the roll result.
The following dice formats are supported:
Format Pattern Example Description XdY 3d8 Simple format. Roll a Y-sided die X times XdYkhZ 2d20kh1 Roll Y-sided die X times and keep the highest Z number of dice XdYklZ 4d6kl3 Roll Y-sided die X times and keep the lowest Z number of dice XdY>Z 5d6>3 Roll Y-sided die X times and count a 1 for each roll greater than Z XdY<Z 5d6<3 Roll Y-sided die X times and count a 1 for each roll less than Z XdYr<Q and XdYr>Q 10d6r<2 Roll a Y-sided die X times, rerolling results less than or equal (or greater than or equal to) to Q XdYro<Q and XdYro>Q 10d6ro<2 Roll a Y-sided die X times, rerolling results less than or equal (or greater than or equal to) to Q one time, keeping the reroll result XdY! and XdY!>Q and XdY!<Q 8d6! Roll a Y-sided die X times, rerolling max results and adding them to the total for the die (or rerolling results >= or <= Q and adding (Exploding dice) XdYkhZr<Q and XdYkhZr>Q 4d6kh3r<1 Roll a Y-sided die X times, rerolling results less than or equal to (or greater than or equal to) Q, and keep the highest Z results XdY!h and XdY!l 4d6!h Roll 1dY X times. If the max number on the dice is rolled, roll it again and add to that die's total. Return only the highest (h) or lowest (l) die roll (Deadlands skill checks). XdF 4dF Fudge dice support. Roll a Fudge die X times, with possible values of +, -, or blank. Roll hover text and .Text will display the values appropriately. XdYW, XdYWS, XdYWH, XdYWSH 4d6W Wild dice support (as seen in games like d6 system). X-1 dice of Y sides will be rolled normally. 1 die of Y sides will be rolled as an exploding die. If the "S" modifier is specified, the Wild die will eliminate itself from the total if the first roll on it is a 1. If the H modifier is included, a 1 on the initial Wild die will remove the highest die amongst the non-wild dice. None, one, or both can be specified. XuY 3u8 Roll a Y-sided die X times, but only generate unique values. If X is greater than Y, only Y dice will be rolled.
(Note: As of writing this (v 1.7.7 and likely previous versions too), Y cannot equal 0. The result of rolling Xd0 is the error "NaN" where the result should be.)
The following operators are supported in a roll equation:
Operator Operation + Addition - Subtraction * Multiplication / Division \ Integer Division (Rounds down) % Modulo (Remainder of Divison)
Roll Variables can be accessed at any time after they have been created by using the [$VariableName] format, with the following optional modifiers (Note that roll modifiers are case sensitive):
Modifier Meaning No modifier In a Direct Output Line (--+) will be replaced with a formatted roll display, including a mouseover with roll text details. In any other type of line, will display the same results as .Total .Total The end result of the roll equation as an unformatted number .Base The cumulative result of any dice rolled in the Roll Text (Numeric modifiers are not included) .Ones The number of dice in the roll that came up as 1s .Aces The number of dice in the roll that came up as the maximum number on the die .Odds The number of dice in the roll that came up with an odd number .Evens The number of dice in the roll that came up with an even number .RollText The raw text of the roll that was use to generate the results .Text A text representation of the results of the roll, including the numbers rolled for each die .tableEntryText The text portion of the result of a table roll .tableEntryImgURL The image source portion of the result of a table roll .tableEntryValue Numeric value of tableEntryText (via parseInt). If a non-numeric value, will be 0 .Raw The total numeric result without any formatting, even if placed somewhere formatting would normally be done. .RollCount The total number of actual dice rolled to make up the roll calculation. If multiple dice are rolled in a single roll set, the results of each die will be counted. ***v1.7.0*** .RolledDice(x) A 1-based "array" of the dice rolled during a roll assignment. If multiple dice are rolled (ie, 1d20 + 1d4) the results of all of the die rolls will be concatenated into the array. ***v1.7.0*** .KeptCount The number of dice rolled that have not been eliminated by a KH or KL clause. If the roll does not contain a KH or KL clause, this will be the same as RollCount. ***v1.7.0*** .KeptDice(x) A 1-based "array" of the rolled dice that were kept after processing a KH or KL clause. It the roll does not contain a KH or KL clause, all of the rolled dice will be included. ***v1.7.0*** .DroppedCount The number of dice dropped from the roll due to a KH or KL clause. If the roll does not contains a KH or KL clause, DroppedCount will be 0. ***v1.7.0*** .DroppedDice(x) A 1-based "array" of the rolled dice that were dropped from the total after processing a KH or KL clause. If the roll does not contain a KH or KL clause, no dice will be added. ***v1.7.0***
Examples:
--+Total Damage|[$MissileDamage.Total] (roll was 1d4+1) --+Base Damage|[$MissileDamage.Base] (without the +1) --=Attack|1d20 + @{selected|strength_mod} [STR] + @{selected|pb} [PROF] + [$BlessBonus] [Bless]
In this case, 1d4 will be rolled and stored in “BlessBonus”, which can then be used in the Attack line.
Mathematical Functions in Roll Expressions
The ScriptCards roll parser works from left to right, always maintaining a current value and applying whatever comes next to the total. The functions here below can be added to a roll expression:
Expression Meaning {ABS} Absolute Value {CEIL} Ceiling value (round up to the next whole number) {FLOOR} Floor value (round down to the next whole number) {ROUND} Round value (round up if the decimal portion is greater than 0.5, otherwise round down) {ROUND:X} Round value to X decimal places (round up if the decimal portion is greater than 0.5, otherwise round down) {NEGATE} Multiply the value by negative one. {SQRT} Take the square root of the running value. {SQUARE} Square the running value. {CUBEROOT} Take the cube root of the running value. {CUBE} Cube the running value. {SIN} Return the SIN of running value. {COS} Return the COS of running value. {TAN} Return the TAN of running value. {ASIN} Return the ASIN of running value. {ACOS} Return the ACOS of running value. {ATAN} Return the ATAN of running value. {MAX:X} Caps the running value at X. (v1.4.12) {MIN:X} If the running value is less than X, set the value to X. {CLAMP:X:Y} Adjust the running value to remain between X (lower bound) and Y (upper bound) {PAD:X} Whenever the .Raw or .Total (same as no suffix) gets displayed, leading zeros will be added to the number to make it at least X digits long (ex. {PAD:3} would result in 5 being displayed as 005). Note that this can have a negative impact on conditional statements if they are being used as string comparisons instead of numeric comparisons.
Here are the syntax rules when using the above listed functions:
Example 1.
!script {{ --=output|2.9 {FLOOR} --+output|[$output] }}
The output from this example is "2".
Example 2.
!script {{ --=output|2.9 {FLOOR} {NEGATE} - 3 --+output|[$output] }}
The output from this example is "-5".
Basically, a function will use as its input whatever the current "running total" is.
Please note that there must always be a space between the function expression and its input. For example, "2.9 {FLOOR}" will work, but "2.9{FLOOR}" will not work.
Special Notes about Dice Rolls (READ THIS!): In order to support the ability to include Roll Variable values in rolls, ScriptCards does not use the built-in Roll20 dice rolling engine, and does not support “inline rolls” (rolls included with [[ ]] in the card). Because I have included my own roll parser, there may be some odd roll methods that are not currently implemented. If you run into dice roll options that don’t work, please let me know and I’ll try to support them.
Special Notes Update: As of version 1.2.3, inline rolls will be parsed by ScriptCards, using only the FINAL RESULT of the roll. The components (dice, modifiers, etc.) will not be visible to ScriptCards.
Rolling on Rollable Tables You can also roll on a rollable table using the expression [T#tablename], where tablename is the case-sensitive name of the table in your game. Proper weighting for each entry in the table is taken into account when rolling on rollable tables. The .tableEntryText and .tableEntryImgURL properties of the Roll Variable will be set to the matching values on the resultant table entry.
Roll Variable Lines do not produce output lines on the card.
String Variable Assignment (--&)
See the Variables-section for more information on String Variables
String variables function in most ways like roll variables, except that they do not attempt to process any dice rolls, and do not have the list of properties that a roll variable has. They are designed to simply contain text. To assign a string variable, use the --&
statement:
--&<String Variable Name>|[+][Content]
Examples:
--&MyText|Hello --&First|Alpha --&Last|Omega --&Final|[&First] [&Second] --&Phrase|The quick brown fox --&Phrase|+ jumped over the lazy dog
The first example simply assigns the word "Hello" to the MyText string variable. The second and third examples similarly assign "Alpha" and "Omega" to the First and Last string variables. The fourth example uses string variable referencing to set the value of Final to what is in First, a space, and what is in Last, resulting in "Alpha Omega" being in Final.
The last two examples demonstrate using the "+" modifier to add text to an existing string variable. Phrase is initially set to "The quick brown fox", and then " jumps over the lazy dog" is added to it because the first character of the content is a "+" symbol, indicating that the content should be added to the variable instead of replacing it.
As indicated in the fourth example above, string variables are referenced using the syntax [&variablename]
Call Mod (--@)
ScriptCards can use a Call API instruction to execute other Mod commands. The Tag contains the Mod command to use (alter, or roll20AM, for example - do not include the !
) The content portion of the statement contains the parameters that are passed to the API script. Because the -- sequence can't be used here, an underscore (_
) at the beginning of the line or preceded by a space is replaced with --
before the Mod command is executed.
Examples:
--@eh|list --@alter|_target|@{target|token_id} _bar|3 _amount|-[$Damage]
In the first example above, the command !eh list
will be executed, calling EncounterHelper. In the second, AlterBars(Forum) is called to modify a token's Bar 3 value.
Note: When ScriptCards (or any Mod script) runs other Mod script commands, there is not an associated player attached to the executed command. This means that the script being called won't know if the person running the ScriptCard is, for example, a GM. The most common instance of this is when calling !token-mod
and trying to use --ids
instead of acting on selected tokens. Since this is an ability normally limited to GMs, you need to enable "Players can IDs" (in !token-mod config).
See API:Script Index for more options.
Branch Label (--:)
A branch label defines a line in your code that can be reached by one of the branching instructions (--^
, -->
, or --?
). The Tag serves as the label name, and must be unique on the card.
The vertical bar (|
) separator must be present, but the content portion of the line is unused and can be treated as a comment.
Examples:
--:MyLoop| --:CriticalHit|Will jump here if we roll a critical hit!
A Branch Label line does not produce an output line on the card.
Branch (--^)
A Branch line jumps execution to the label indicated by the Tag. The vertical bar (|
) separator must be present, but the content portion of the line is unused and can be treated as a comment.
Examples:
--^MyLoop|Jumps to MyLoop --^SkipCrit|We didn't crit, so skip the Crit code
A Branch line does not produce an output line on the card.
Call Procedure (-->)
Similar to a branch, a Call Procedure (sometimes knows as a "gosub") line branches execution to the label indicated by the Tag. However, the return pointer of the call will be pushed onto a stack so that a Return instruction (--<
) will return execution to the next line in the card. A list of parameters for the subroutine can be passed as the content portion of the tag, and are separated by semicolons (;
).
--><Procedure Label>|[Parameters (Separated by semicolons (;)]
Examples:
-->FixFormat|#3333FF;#999999
In this example, a label called FixFormat
will be branched to as a subroutine, passing the parameters #3333FF
and #999999
. In the subroutine, these parameters are referenced by number as [%1%]
and [%2%]
.
Return (--<)
A return instruction marks the end of a Gosub procedure. Execution will return to the statement after the one that called the subroutine. The Tag and Content portions are both optional, but the vertical bar separator must be included.
--<|
Examples:
--<| --<|End of MySub
In both cases, the value of the tag and the content portions of the statement are ignored, but the vertical bar separator must still be present.
Conditional Statement (--?)
See the Variables-section for more information on Variables
See the Referencing-section for information on referencing variable content
A conditional statement contains some equation in the Tag that will be evaluated. If any part of the comparison can/does contain a space, it needs to be surrounded by double quotes
Based on the true/false result of the evaluation, one of two execution paths will be taken. These execution paths are detailed in the content section of the statement. The "if true" path is specified first (directly after the vertical bar), and the "if false" path is specified after it, also separated by a vertical bar.
Example:
--?[$AttackRoll.Total] -ge [$TargetAC]|Hit|Miss
Prior to version 1.2.1, all conditional statements resulted in either a branch to a label statement, or a gosub branch. As of version 1.2.1 additional options for what happens when a condition is matched were added, and 1.2.5 adds further additional functionality.
Branch Format Meaning Label If just a label is specified, execution will branch to that label when the comparison is matched. >Label If a label name is preceded by a ">" character, a gosub branch will be performed. In this case, parameters can be passed to the subroutine by separating them from the label and each other with semicolons (;). Parameters that can contain a semicolon (like token/character IDs) should be surrounded by double quotes =VariableName The roll variable "VariableName" will be assigned the value following a semicolon (for example, the code "=Roll;1d20" will assign the value "1d20" to a variable named "Roll", if the condition is true). &VariableName The string variable "VariableName" will be assigned the value following a semicolon (for example, the code "&Result;Hit" will assign the value "Hit" to a variable named "Result", if the condition is true). % or %! The current for...next loop will perform the "next" action (%) or will break out (%!) [ Code block (see below) In ScriptCards v2.1.7+ < Return from the currently executing subroutine +Tag;Content Create a Direct Output line (ie, --+) with the Tag portion in bold and the Content portion in normal text *Tag;Content Create a GM-Only Output line (ie, --*) with the Tag portion in bold and the Content portion in normal text
Examples:
--?[$AttackRoll.Base] -eq 20|CriticalHit --?[$AttackRoll.Base] -eq 1|>Fumble;@{selected|dexterity_mod} --?"@{target|npc_type}" -inc "undead"|&MonsterType;Undead|&MonsterType;Not Undead --?[$Attack.Total] -ge [$ArmorClass]|>Hit|>Miss
In the first example, if the Base value of AttackRoll is a 20 (natural 20 on the die) execution will branch to the CriticalHit label.
In the second example, if the Base value of the AttackRoll is 1 a gosub branch will be executed to the "Fumble" label, and passed the value of the selected character's dexterity_mod as parameter [%1%].
The third example looks for the word "undead" in the npc_type attribute of the targeted character. If it exists in the text, the MonsterType string variable will be set to "Undead", otherwise it will be set to "Not Undead".
The final example would call the "Hit" procedure on a hit and the "Miss" procedure on a miss and return execution to the next line after the procedure calls were finished.
Text that does/may contain a space should be enclosed in double quotes.
The following comparison operators are available:
Comparator Meaning -eq Equal To -eqi Case insensitive Equal To -ne Not Equal To -nei Case insensitive Not Equal To -gt Greater Than -ge Greater Than or Equal To -lt Less Than -le Less Than or Equal To -inc Includes (text strings - not case sensitive). -ninc Does Not Include (text strings - not case sensitive).
Multi-part conditionals are supported with -and and -or as separators. For example:
--?[$Attack.Total] -ge @{target|npc_ac} -and [$Attack.Base] -ne 20|HitButNotCrit
Multi-part conditionals are evaluated from left to right, and each evaluation is either ANDed or ORed with the current cumulative state. This means that (assuming "true" and "false" are actually conditional expressions that evaluate to either true or false):
true AND false OR true
Will be evaluated as true. The first two (true and false) will be false, but then false OR true will be true.
Conversely:
true or false and false
Will be false, because the first true and false will evaluate to true, and then true and false will be false.
CODE BLOCKS
A new feature (1.2.7), code block allow you to treat a group of statements as a single unit based on a condition. This is similar to begin...end or curly braces in some languages, though a bit more limited. As part of the true or false execution branch of a conditional, you can use the "[" character to begin a code block.
If that execution path is taken, the code in the block will be executed. Otherwise, the code in the block will be skipped. Blocks are completed with the --]|
statement, and can optionally include an "else" block by using --]|[
as the block terminator. Here is an example:
!script {{ --=Roll|1d2 --+Roll|[$Roll] --?[$Roll.Total] -eq 2|[ --&Value|Yep! --+|We are inside the TRUE portion of the block --]|[ --&Value|Nope --+|We are inside the FALSE portion of the block --]| --+After|the blocks! --+Value|[&Value] }}
In this case, we begin by rolling 1d2 and then use a conditional to see if the result is 2. if it is, we execute everything inside the code block that begins on the conditional line, up until the end of the block marked with --]|[
because we have an "else" block. The else block is terminated with --]|
.
At this time, blocks cannot be nested, and can only be created as part of a conditional (--[
is not a valid statement type)
A conditional statement does not produce a line of output on the card.
Case Statement (--c)
See the Variables-section for more information on Variables
See the Referencing-section for information on referencing variable content
The case statement (--c
) allows you to specify a value to test as the tag and a list of possible matches. These matches are case-insensitive. Matching groups are separated with vertical bars and matches and their branch labels are separated by a colon (:
). It is also allowable to use Roll Variable or String Variable assignment syntax instead of a branch label, just as with the --?
statement. If none of the values are matches, the script will simply proceed onto the next line. Both direct and procedure branches are supported, and procedure branches can include parameters as normal. Example:
!script {{ --#title|Case Statement Testing --=Roll|1d4 --C[$Roll.Total]|1:>One;[$Roll]|2:>Two;[$Roll]|3:>Three;[$Roll]|4:>Four;[$Roll] --X| --:One| --+Value|was One ([%1%]) --<| --:Two| --+Value|was Two ([%1%]) --<| --:Three| --+Value|was Three ([%1%]) --<| --:Four| --+Value|was Four ([%1%]) --<| }}
This script uses the value of [$Roll.Total]
and compares it against 1, 2, 3, and 4, using a gosub branch to the matching value. The first match test is 1:>One;[$Roll]
, where 1
is the value being matched, followed by a procedure branch to One
which gets the roll variable as a parameter.
As a further example, the case statement below uses the value of a roll query to assign a Roll Variable based on the query result:
--c?{Difficulty|10|20|30|40}|10:=BonusHealing;0|20:=BonusHealing;10|30:=BonusHealing;30|40:=BonusHealing;50
The $BonusHealing
variable will then contain either 0
, 10
, 30
, or 50
depending upon the user's choice.
Using this syntax, the first example in this section could be rewritten as:
!script {{ --#title|Case Statement Testing --=Roll|1d4 --C[$Roll.Total]|1:&Result;One|2:&Result;Two|3:&Result;Three|4:&Result;Four --+Value|was [&Result] ([$Roll.Raw]) }}
Instead of branching, this example assigns the string variable &Result
to "One", "Two", "Three", or "Four" depending on the output of the roll and displays it along with the $Roll
itself.
Save and Load (--s and --l)
This statement pair is used to either store (--s
) or load (--l
) data from persistent storage. Items stored in persistent storage remain between card rolls and between Roll20 sessions. There are two types of data that can be stored: settings and roll variables.
Examples:
--Ssettings|GreenStyle --Srollvariables|FirstCardVars
In this case, the tag for the statement determines what type of item is being saved (settings or rollvariables). When saving settings, all non-default settings are written to the named setting storage value. When Roll Variables are saved, all variables that currently exist will be saved to the named storage value.
Loading stored items simply requires the same command with the --l
statement type:
--Lsettings|GreenStyle --Lrollvariables|FirstCardVars
When loading settings, all stored settings will be applied to the current card settings. You can override settings by changing them after the load.
When loading roll variables, the saved variables will be added to (or overwrite if they have the same name) any variables on the current card. This means it is safe to create roll variables before the load statement.
Practical Uses The major intended use of persistent storage is for storing card formats for use in later scripts. For example, the following script:
!scriptcard {{ --#titlecardbackground|#22CC22 --#oddrowbackground|#cceecc --#evenrowbackground|#99ee99 --Ssettings|@{selected|token_name} }}
Would save the titlecardbackground
, oddrowbackground
, and evenrowbackground
settings to a saved list named after the selected token's name. When creating cards for that token to run later, you could include the line:
--Lsettings|@{selected|token_name}
To load all of the settings at once. By creating these setting sets for each character, you can specify a different color scheme for each character that can then be used in cards with a single formatting line.
There is a supplemental !
command added to support saved settings:
!sc-liststoredsettings
Will produce a list of all stored setting names, with buttons to list the setting values stored in each group and a button to delete groups as needed.
Visual Effects (--v)
The --v
statement allows you to create visual effects on the VTT. The tag portion of the statement (before the |
) specifies the location of the effect. The standard statement format for --v
is:
--v<Location Specifier>|< X Y | Token_ID | Token_ID Token_ID> <Effect Specifier> [moveall]
Location Specifiers
There are three potential location specifiers, each of which requires a different number/type of parameters, which are passed in the content portion of the command:
Location Specifier Effect Location Effect Types Notes point X and Y Coordinate on the map specified by first two parameters of content bomb, bubbling, burn, burst, explosion, glow, nova, ping* and custom** Upper left corner of the map is 0 0 token The center point of a specified token (by Token ID) bomb, bubbling, burn, burst, explosion, glow, nova, ping* and custom** None betweentokens Used for line-stlye effects. Two Token IDs are required beam, breath, missile, splatter and custom** First token will be the effect source, and second token determined the direction
(* see notes on the ping specifier below) (** Custom effects can be created in the Roll20 VTT and their names can be used as specifiers for effects)
Effect Specifiers
Roll20 provides 11 pre-defined effect types and 11 pre-defined effect colors. An effect specifier is comprised of a type, followed by a dash (-
), followed by the color:
burst-fire explosion-magic breath-acid
Available effect types: beam
*, bomb
, breath
*, bubbling
, burn
, burst
, explosion
, glow
, misisle
*, nova
, splatter
*
(* These effects are line/direction based and only function with the betweentokens location specifier)
Available effect colors: acid, blood, charm, death, fire, frost, holy, magic, slime, smoke, water
Note: Effect types and colors are case sensitive (all lower case).
Examples:
--vpoint|250 250 explosion-magic --vtoken|@{selected|token_id} nova-water --vbetweentokens|@{selected|token_id} @{target|token_id} beam-acid
Pings
As of version 2.0.0, it is now possible to use "ping" as a special type of effect specifier. When used, the VTT will ping the given location (either an X/Y coordinate or the center point of a given Token_ID). This is the same effect that users can create by holding down their mouse button at a location on the map. It is also possible to specify the "moveall" modifier at the end of the command to re-center all player's views on the pinged location.
Examples:
--vtoken|@{selected|token_id} ping --vpoint|150 150 ping moveall
Audio Effects (--a)
The --a statement plays an audio track from your Roll20 jukebox by name. The content value of the statement specifies the case-sensitive name of the track to play. If the jukebox track does not exist, no sound will be played, and a warning will be output to the API console log indicating the missing track.
--a|< Jukebox Track Name>
Example:
--a|SwordHitSound --a|Woodland_Exploration_Ambient
No external APIs are required.
Echo to Chat (--e)
The echo statement is simply a call to the API's sendChat command, using the tag as the speakingAs parameter and the content as the text to send.
--e[Speaking As]|[ Text to Speak ]
Example:
--eThe Ghost|/em hovers around @{selected|character_name}... BOO!
Would output "The Ghost hovers around (charactername)... BOO!" as an emote to chat. This will happen whether or not you have a character named "The Ghost" in your journal or not (roll20 sees this message as coming from the API, not from a player or a character).
Whispering
You can use the echo statement to send a whisper, but there's a trick to it. If you execute this code here:
--eThe Ghost|/w ExamplePlayerName Boo.
Then the player named "ExamplePlayerName" would see on his screen a whisper from "The Ghost" that says "Boo."... but you would not see anything on your screen! And you wont see anything on your screen no matter what you try to replace "The Ghost" with... not even if you try to use "GM" or your own player name. Because, again, roll20 sees the message as coming from the API, not from a player or a character.
So, in conclusion, it's best to use something like this when you're sending a whisper:
!script {{ --#hidecard|1 --&sender|The Ghost --&receiver|ExamplePlayerName --&message|Boo. --e[&sender]|/w [&receiver] [&message] --eScriptCards|/w gm **Whispered from [&sender] to [&receiver]:** [&message] }}
This will ensure that the message appears in your chat feed as well.
Repeating Section Access (--R)
See the Referencing-section for information on referencing repeating section content
Roll20 provides a mechanism for character sheet authors to allow for entries for data types that can be repeated on the same sheet via Repeating Section rows (ex, weapons, actions, inventory, etc.) Repeating sections can potentially be one of the most complicated and confusing Roll20 systems to work with, and ScriptCards tries to streamline this process via the --R
statement type.
--r<subcommand>|< parameters >
In the examples below, the following terms will be used:
- Sub Command - This specifies exactly what you want the
--R
command to do - Character_Id - Refers to the internal ID associated with a character. One method for retrieving the ID is
@{selected|character_id}
- Section Prefix - Repeating sections each have a prefix name associated with the section. For example, in the D&D 5E by Roll20 sheet,
repeating_attack
is the section prefix for the portion of the player character sheet that contains any defined attack options. For NPCs,repeating_npcation
is the section prefix for NPC Actions. Note that these will be character sheet specific. - Repeating Row - A repeating section can contain 0 or more rows. Each row contains all of the information for a given entry in the section.
- Row Index - Rows in a repeating section are numbered starting at 0, and often referenced in the chat window as
@{selected|repeating_attack_$0_atkname}
or something similar. The 0 in this case represents the index of the first row in the section. - Field - A repeating section row consists of any number of fields, specifying entries like name, damage, range, and the like.
- SearchText - Represents a string that you will be looking for in a field.
Working with Repeating Section data
ScriptCards handles repeating sections by loading a single row from a single repeating section into memory at a time and then allowing you to reference the fields associated with that row. You can move through the rows in a section sequentially, by index, or by searching for a particular item.
There are several subcommands available when using the --R
statement:
Sub Command Parameters Description first Character_Id;Section Prefix Loads the first row from the repeating section defined by Section Prefix into memory next none Loads the next row from the current section into memory (used after --Rfirst) find Character_Id;SearchText;Section Prefix;Field Searches the "Section Prefix" repeating section looking for "SearchText" in the field named "Field" and loads the matching row into memory byindex Character_id;Section Prefix;Index Loads the entry matching "Index" from the Section Prefix repeating row into memory dump none Outputs all of the available fields for the loaded repeating section row to the Mod Scripts console for debugging or research
Examples:
--Rfind|@{selected|character_id};Greatsword;repeating_attack;atkname
Will look at the character's repeating_attack
section for an entry with an atkname
value equal to "Greatsword".
--Rfind|@{selected|character_id};Bite;repeating_npcaction;name
Will look for a "Bite" action on the character's repeating_npcaction
list.
--Rfirst|@{selected|character_id};repeating_attack
Would load the character's first repeating_attack
row into memory.
--Rnext|
No parameters are required for --Rnext
, which loads the next entry in the list that was obtained with "first" into memory.
--Rbyindex|@{selected|character_id};repeating_attack;4
Loads the character's 5th repeating_attack
entry into memory (NOTE that index numbers start a 0
to match Roll20's $X
numbering system)
Section prefixes and how to use them
To see the complete list of the section prefixes for the "D&D 5E by Roll20" character sheet, as well as a nice explanation for how to use them, please open this page, and search for the phrase "repeating sections" under the Advanced Use-section.
For other character sheets, you will need to view the documentation on those sheets, or examine the character sheet code live through Browser Developer Tools, or go look at the sheet sourcecode if it's available on the character sheet repository.
Additional information
However a row is obtained, it will be parsed to replace any attribute references (ie, @{level}
) with the corresponding character attribute.
If at any point, a valid entry isn't found (find doesn't find something, first doesn't see any rows, or next goes off the end of the list) any attempts to reference the row data will return "NoRepeatingAttributeLoaded".
You can reference repeating attribute data using the syntax [*R:attributename]
syntax (similar to referencing standard character attributes).
Here are some examples:
Display the details of the "Greatsword" PC attack:
!script {{ --Rfind|@{selected|character_id};Greatsword;repeating_attack;atkname --+Attack Name|[*R:atkname] --+Base Damage|[*R:dmgbase] }}
List all of the actions an NPC can take (just actions, not legendary, etc.)
!script {{ --#title|NPC Actions --#sourcetoken|@{selected|token_id} --Rfirst|[*S:character_id];repeating_npcaction --?"[*R:name]" -eq "NoRepeatingAttributeLoaded"|END --:NPC_Action_Display| --+[*R:name]|[*R:description] --Rnext| --?"[*R:name]" -ne "NoRepeatingAttributeLoaded"|NPC_Action_Display --:END| }}
In the script above, we get the "first" repeating_npcaction
and check to make sure it exists (ie, [*R:name]
doesn't return "NoRepeatingActionLoaded". As long as we have a valid repeating row, we display the name and description of the action.We then execute "next" and repeat until we run into "NoRepeatingAttributeLoaded", indicating that we have run out of repeating_npcaction
rows.
See the Repeating Section Values-section for more information.
Special debugging command: dump
--Rdump|
The "dump" command will list all of the attributes ScriptCards knows about for the currently loaded repeating row to the API Console Log.
Built-In Function (--~)
ScriptCards has the ability to run a function built into the API script and return the results to a variable. Some functions return roll variables, while others return strings. Functions are grouped into several different categories. There are a handful of functions without a category, in which case the category is omitted from the call. The general format for a --~
call is:
--~[Variable Name]|<Category>;<Function>;[parameter];[parameter]...
The following functions do not have categories associated with them, and can be called simply with --~[Variable Name]
Function Name Parameters Description distance token_A_ID;token_B_ID Calculate the Chebyshev distance in grid units between two tokens. This is the measurement scheme D&D 4E/5E use for diagonal distance measurement euclideandistance token_A_ID;token_B_ID Calculate the Euclidean distance between two tokens. This is essentially the Pythagorean theorem in action. Returns the result in grid units. euclideanpixel token_A_ID;token_B_ID Calculate the Euclidean distance between two tokens and returns the result in pixels instead of grid units. euclideanlong token_A_ID;token_B_ID Calculate the Euclidean distance between two tokens and returns the result in grid units, but the grid unit conversion is performed AFTER the pixel distance is calculated instead of before. More accurate over long distances. manhattandistance token_A_ID;token_B_ID Also called "taxicabdistance" (which is an acceptable function name), this measures to how-many-over, how-many-up/down distance, disallowing diagonal movement. getselected none Using the variable name in the tag, a series of string variables will be created: VariableNameCount will contain the number of selected tokens. VariableName1 will contain the token ID of the first selected token, VariableName2 the second, etc.
Categorized Functions
Most ScriptCards functions are grouped into several major categories. The table below lists the function categories and their sub functions within each category.
Category Name Function Name Parameters Return Type Description array define arrayname;value1;value2;... none Creates an array called "arrayname" and adds value1, value2, etc. to the array array sort arrayname(;descending-optional) none Sorts the specified array in place in ascending order (alphabetically). array numericsort arrayname(;descending-optional) none Sorts the specified array in place in ascending order (numerically). array add arrayname;value1;value2;... none Adds value1, value2, ... to the existing array "arrayname" array remove arrayname;value1;value2;... none Removes value1, value2, ... from the existing array "arrayname". Resets the array index to 0. array replace arrayname;currentvalue;newvalue none Replaces all occurrences of "currentvalue" in "arrayname" with "newvalue" array setatindex arrayname;index;newvalue none Replaces the array item at index "index" with "newvalue" array getindex arrayname stringVariable Retrieves the current index in "arrayname" and stores it in the supplied string variable array setindex arrayname;newindex none Sets the current index in array "arrayname" to "newindex" array getcurrent arrayname stringVariable Gets the item at the current array index in "arrayname" and returns it as a string variable. Will return "ArrayError" if there is no current item. array getnext arrayname stringVariable Increments the current index in "arrayname" and returns the new current value. Will return "ArrayError" if the end of the array is reached. array getprevious arrayname stringVariable Decrements the current index in "arrayname" and returns the new current value. Will return "ArrayError" if the the current index was already zero. array getfirst arrayname stringVariable Set the current index of "arrayname" to zero and retrieve the current item. Will return "ArrayError" if there is no current item. array getlast arrayname stringVariable Set the current index of "arrayname" to the last item in the array and retrieve the current item. Will return "ArrayError" if there is no current item. array removeat arrayname;indexposition none Removes the item at index "indexposition" from "arrayname". Resets the current array index to 0. array indexof arrayname;searchvalue stringVariable Searches the array "arrayname" for an item with the value of "searchvalue" and, if found, returns the index of the first matching value or "ArrayError" if not found array getlength arrayname stringVariable Returns the number of items in array "arrayname" array pagetokens arrayname;tokenid OR pageid;(optional filter) stringVariable Creates an array (arrayname) of all of the token ids (technically Graphics objects) on the same page as the specified token id or on the page matching the page id. Returns the number of tokens found to the stringVariable. Available optional filters are : all, char, graphic, pc, npc. The filters will return only those tokens that match that criteria (char means tokens have a "represents", graphic doesn't. pc indicates a represents token has a controlledby, npc doesn't.) array selectedtokens arrayname stringVariable Creates an array (arrayname) of all of the token ids (technically Graphics objects) selected when the script was executed. Returns the number of tokens found to the stringVariable. array stringify arrayname(;separator-optional) stringVariable Returns all of the items in "arrayname" as a string separated by default semicolon (;) or the current #parameterdelimeter. New in 2.1.0, an additional parameter can be added that specifies the delimiter to be used. array fromstring arrayname;delimiter;string unused Creates an array from "string", splitting "string" on "delimiter" to separate the items array statusmarkers arrayname;tokenid none Creates an array (arrayname) of the active statusmarkers (sometimes called Token Markers) for the specified tokenid array objects:objectype arrayname;filter none Creates an array (arrayname) of the IDs of game objects of the specified type that match the indicated filter. Note that "filter" is really just that the designated field starts with the specified value. The designated field is "name" for all objects with names. For other objects, the filter field is _displayname for players, title for jukeboxtracks, stroke (color) for paths, text for text and not supported for campaign, card, and hand objects. Filters are not case sensitive. array fromrepeatingsection arrayname;charid;repsection name;field name unused Creates an array from the entries in the repeating section defined by repsection name, returning the values of field name as the elements in the array array fromtable arrayname;tablename;"name", "image", or "both" unused Creates an array from the entries in a rollable table. "name" and "image" determine if the entry name or image URL is returned in the array. If "both" is specified, both components will be returned for each array element separated by a vertical bar. array fullrepeatingsection arrayname;charid;repsection name;field1:field2:field...;sepsequence unused Creates an array from the entries in the repeating section defined by repsection name, returning the values of each field specified in the field list parameter (separated by colons). The values in the array entries will be separated by the sepsequence. math angle math;angle;tokenid;tokenid rollVariable Calculates the angle between two tokens and returns the value in degrees math ceil math;ceil;value rollVariable Rounds value up to the next integer, dropping any decimal portion of the number math clamp math;clamp;value;lowerBound;upperBound rollVariable Returns value, but restricted to the range of lowerBound and upperBound. math floor math;floor;value rollVariable Rounds value down, dropping any decimal portion of the number math max math;max;valueA;valueB rollVariable Returns the larger of valueA vs valueB math min math;min;valueA;valueB rollVariable Returns the smaller of valueA vs valueB math round math;round;value rollVariable Rounds value to the nearest integer string length string;length;stringValue rollVariable Returns the length of stringValue in characters string before string;before;searchText;stringValue stringVariable Searches stringValue for searchText and returns the portion of stringValue prior to that text string after string;after;searchText;stringValue stringVariable Searches stringValue for searchText and returns the portion of stringValue after that text string left string;left;count;stringValue stringVariable Returns the leftmost count characters of stringValue string right string;right;count;stringValue stringVariable Returns the rightmost count characters of stringValue string replace string;replace;searchText;replaceText;stringValue stringVariable Replaces searchText in stringValue with replaceText and returns the resulting string string replaceall string;replaceall;searchText;replaceText;stringValue stringVariable Replaces all intances of searchText in stringValue with replaceText and returns the resulting string Requires 1.2.9+ string trim string;trim;stringValue stringVariable Removes leading and trailing spaces from stringValue and returns the result. string substring string;substring;start;count;stringValue stringVariable Returns count characters starting at start from stringValue string split string;split;delimiter;stringValue special Splits stringValue into pieces, breaking it at delimiter. Returns a rollVariable with "Count" appended to the assigned variable name and a series of string variables with numbers appended (starting at 1) for each of the returned pieces. string tolowercase string;tolowercase;stringValue stringVariable Converts the passed string to lower case and assigns to the passed variable name. string touppercase string stringVariable Converts the passed string to upper case and assigns to the passed variable name. string totitlecase string stringVariable Converts the passed string to title case (capitlaizes the first letter of each word) and assigns to the passed variable name. string onlynumbers string stringVariable Returns only the number values from a string, preserving a leading - sign if it is the first non-whitespace character in the string. string nonumbers string stringVariable Returns a string with all numeric characters (0 thru 9) removed. stateitem write stateitem;write;variableType None Writes the variable specified in the tag to persistent storage. Specify either rollvariable or stringvariable for variableType. One of each type can be stored in persistent storage at a time. stateitem read stateitem;read;variableType Depends on variableType Reads the stored variable of the specified type (either rollvariable or stringvariable) and stores the result in a variable named for the line tag. turnorder clear none none Clears all entries from the t Turn Tracker/Initiative turnorder addtoken tokenid;trackervalue none Adds the token represented by "tokenid" to the initiative tracker with an initiative value of "trackervalue" turnorder replacetoken tokenid;trackervalue none Replaces the token represented by "tokenid" in the initiative tracker with an initiative value of "trackervalue". Will add the token if it doesn't exist in the tracker. turnorder removetoken tokenid none Removes the token represented by "tokenid" from the initiative tracker if it exists turnorder addcustom textlabel;trackervalue;(optional)formula none Add a custom text entry to the t Turn Tracker/Initiative named "textlabel" with an initiative value of "trackervalue" turnorder removecustom custom name none Removes the custom turn order token matching the given name from the turn tracker turnorder sort none or "a" or "u" none Sorts the turn order in descending numerical order unless the additional "a" or "u" parameter is set ("a"scending or "u"p). Version 2.1.1 system date getdatetime stringVariable Returns the date time in the active timezone (see settings) system date getdate stringVariable Returns the date in the active timezone (see settings) system date gettime stringVariable Returns the time in the active timezone (see settings) system dumpvariables "rolls", "string", or "array" none Dumps all of the defined variables of the indicated type to the console log system findability system;findability;charactername;abilityname stringVariable Returns the object ID of the ability on the indicated character or "AbilityNotFound"
Examples:
This example uses a function without a category, returning the HowFarAway roll variable as the result:
--~HowFarAway|distance;@{selected|token_id};@{target|token_id}
This example uses a function in the turnorder category. There is no return value for the turnorder/addtoken function:
--~|turnorder;addtoken;@{selected|token_id};5
Information Request (--i)
An Information Request statement allows your script to pause and “ask” the user for additional input. The statement type is --i
, and uses the Tag portion of the statement to define a prompt to the user and the caption of a button that will be displayed for the user to press to provide additional information. The content portion of the line is made up of a series of information request in the format type;VariableName;PromptText
, with each request separate by double vertical bars.
--i<Text Prompt>|< Type;VariableName;Prompt >...
ScriptCards will use the display text and the button caption to whisper the script sender a message with a button to click that can ask for information via roll queries or ask for targets to be selected. Multiples of each type and combinations are allowed. The result of each information request will be stored in a string variable matching the VariableName
parameter for that request.
After the user has clicked the button and responded to the requests, ScriptCards will resume processing the script from where it left off.
Here is an example “i” line:
--IScriptCards needs additional information to continue;Click to select a target and provide information|t;MyNewTarget;Missile1Target||q;MyNameIs;What is your name?
The sample above will whisper the user "ScriptCards needs additional information to continue" and provide a button labeled "Click to select a target and provide information". When the user clicks the button, they will be requested to select a target labeled Missile1Target
and a prompt will appear asking that they enter their name into a text field.
Supported information request types are “t” for target token, and “q” for query.
For “t” types, specify the variable name to store the token ID in as the second parameter and the prompt text that will appear in the “Choose Target” window (i.e. Choose Target: Missile1Target above).
For “q” types, specify the variable name to store the response in as the second parameter, and the text of the roll query without the ?{}
identifiers. You can specify values for dropdowns, etc. For example:
q;UserName;What is your name?|Fred|Bob|Sally|Nancy
Would have a dropdown menu with four choices.
Object Modification (--!)
ScriptCards supports direct manipulation of object properties within your script. While updating object properties is possible by utilizing the --@
command to call external Mod (API) scripts, the biggest advantage of doing this directly through ScriptCards is that the modifications to the objects take place immediately, so reading values back works as you would expect.
General syntax:
--!<objectType>:<objectId>|[setting:value]|[setting:value]|[setting:value]...
objectType can be one of "t" for token, "c" for character, or "a" for character attribute
NOTE: As of version 2.1.0, any Roll20 object type is now supported as well. As of this writing, the Roll20 object types are: campaign, player, page, path, text, graphic, character, attribute, ability, handout, macro, rollabletable, tableitem, deck, card, hand, jukeboxtrack, custfx.
objectId can be a token id or a character id (or "S"/"T" for the Source/Target token/char defined with --#sourcetoken and --#targettoken)
NOTE: As of version 2.1.0, this can refer to any type of object, but will only function if the object is of the type specified by the objectType parameter.
setting and value pairs can be chained in a single statement separated by | to impact more than one property/attribute with a single line
When using the "t", "c", and "a" object types, values can be prefixed with +=
or -=
to add/subtract from the current value (no bounds checking is done). Using [*X]
notation, the updated values can be read immediately. Using +=
or -=
on non-numeric data will simply result in a string append. NOTE: using the extended object types in 2.1.0 does not support +=
and -=
. If you need this functionality, you will need to implement it manually in order to keep these commands as open and powerful as possible.
For "a" types, setting names can be prefixed with a !
to create the attribute if it doesn't exist (by default, it will not be created), and postfixed with ^
to set the max value instead of the current value.
Note that there are VERY few attributes associated with a character object, and there are likely few cases where you would want to set anything on the character object, but it is still possible.
As of version 2.1.7, Object modification statements now support the ability to modify any type of object by specifying the object type and object id in the tag portion of the statement. Note that very little checking is done on this (if the property you are setting is imgsrc, the image source will be reformatted per Roll20 requirements).
When setting values listed in the Roll20 Object API as boolean types, use the words "true" or "false" to indicate the desired value.
Ex: --!graphic:@{selected|token_id}|bar1_value:256
Will set the "bar1_vlaue" property of the selected graphic object to 256. As with variable referencing, you are likely better off using the specific object type commands (ie, --!t: and --!a:, etc.) when they are available. Note that setting Bio, Notes, and GMNotes will actually make the setting, but it isn't immediate and will not necessarily be available if read back within the same script. It will also throw a console message about needing to pass a callback.
Examples:
Set the value of bar1_value for the selected token to 5:
--!t:@{selected|token_id}|bar1_value:5
Add 1 to the bar3_value for the selected token:
--!t:@{selected|token_id}|bar3_value:+=1
Set bar2_value to 5 and bar2_max to 10 for the selected token
--!t:@{selected|token_id}|bar2_value:5|bar2_max:10
For the character the selected token represents, set "dndstyling" attribute on, set "size" to enormous, and set "attitude" to epic. The attitude attribute will be created if it doesn't exist on the character already. The same is not true for dndstyling and size:
--!a:@{selected|token_id}|dndstyling:on|size:enormous|!attitude:epic
Adds 50 to the npc_xp attribute for the character represented by the selected token, displaying the value before and after the update:
!script {{ --+XP|[*@{selected|token_id}:npc_xp] --!a:@{selected|token_id}|npc_xp:+=50 --+XP|[*@{selected|token_id}:npc_xp] }}
Note that asynchronous read/update fields (bio
, notes
, gmnotes
) can be set by object modification statements, but the values of these fields cannot be read back into ScriptCards.
Abilites Attributes can be created with the --! command with the following syntax:
--!ob:ReturnVarName:CharacterID:AbilityName:IsTokenAction|Text of the Ability
Note that you will need define string variables for special characters you would like to hide from the Roll20 chat server. The following example adds an ability to the selected character called "SayHello" that uses the "Lightning-Bolt" ability on a character called "Spell_Mule":
!script {{ --&obrac|{ --&cbrac|} --&perc|% --!ob:AbilID:@{selected|character_id}:SayHello:y|[&perc][&obrac]Spell_Mule|Lightning-Bolt[&cbrac] --+AbilID|[&AbilID] }}
To break this line (--!ob:AbilID:@{selected|character_id}:SayHello:y|[&perc][&obrac]Spell_Mule|Lightning-Bolt[&cbrac]) down:
- --! is the start of an object moficiation command
- o means create a new object
- b means aBility ("A" would be reserved for attributes)
- AbilID is the string variable that the object id of the new ability will be returned to
- @{selected|character_id} is filled in with the Character ID of the currently selected character
- SayHello is The name of the ability that will be created
- y says that this ability should show up as a token action button when the token is selected
- [&perc][&obrac]Spell_Mule|Lightning-Bolt[&cbrac] is the text of the ability, with variables used on place of %, { and } to avoid having them processed by the chat server.
You could also include references global macros by creating --&hash|# and placing that before the global macro name in the ability text, Ex:
--!ob:AbilID:@{selected|character_id}:ActionMenu:y|[&hash]ActionMenu
Repeating Rows
You can use the --! command to create repeating rows on character sheets. The syntax is: --!or:character_id:sectionName|value:current:max|value:current:max...
For example, to create a language proficiency on the currently selected character (5E):
--!or:@{selected|character_id}:proficiencies|prof_type:LANGUAGE|name:Abyssal
The max portion is optional and can be left out if it doesn't make sense (as in the line above). A bit more complicated example is below. This creates a repeating_npcaction on the currently selected character (note that ScriptCards doesn't have a way to check to see if the section exists, it will just create the appropriate attributes on the character - again, this is a 5E example, but repeating sections on any sheet can be created as long as you know what attributes you need to specify and the name of the section):
!script {{ --!or:@{selected|character_id}:npcaction| name:Mega Bite| attack_flag:on| attack_type:melee| attack_target:one target| attack_range:5 ft.| attack_tohit:8| attack_damage:1d4 + 3| attack_damagetype:piercing| attack_tohitrange:+5, Reach 5ft., one target| attack_onhit:5 (1d4 + 3) piercing damage| attack_crit:1d4 }}
Note that this is all one ScriptCards line, and could be written that way. Placing each attribute/value pair on its own line makes it a bit clearer to read, though.
ScriptCards will assume that the section starts with "repeating_" so it should not be specified in the section parameter (hence "npcaction" instead of "repeating_npcaction")
Wait (--w)
The --w
command, which has two related methods of use. --w#| (ie, --w5|) will sleep the sandbox for # seconds (up to 10)
Note that this has limited usefulness and multiple delays could crash the sandbox by Roll20 thinking it entered an infinite loop.
The second option is --w#:regularscriptcardsline, for example: --w5:a|CureLightWounds which would run the script normally and
trigger the system to run the ScriptCard line indicated 5 seconds later. This is done by generating a mini ScriptCard containing
that single line. Variable referencing is processed when this mini-card is generated. Example:
!script {{ --&SoundToPlay|Spell_FireBurst --w3:a|[&SoundToPlay] --w4:vtoken|@{selected|token_id} nova-fire --w5:!t:@{selected|token_id}|left:250 }}
This script will run and output the ScriptCards title. Three seconds later, the Spell_FireBurst audio track will play. One second after that, a nova-fire VFX will play at the selected token location, and finally a second after that the token will be moved to x-position 250.
Note: If the delayed command is a direct output (--+) or GM output (--*) command, the mini-ScriptCard will display the line as a new card with the title hidden.
Inline Formatting
Inline formatting is processed on Direct Output lines only (--+
lines) and the following inline format markup is available:
Formatting Tags Description [b]..[/b] Bold the text between the markers [i]..[/i] Italicize the text between the markers [u]..[/u] Underline the text between the markers [s]..[/s] Strike-Thru the text between the markers [c]..[/c] Center alignment [l]..[/l] Left alignment [r]..[/r] Right alignment [j]..[/j] Full justification alignment [f#]..[/f] Set in-line font size to #px. (2.0.2e) [br] Line break (translates to <br>
in html)[hr] or [hr #xxxxxx] Insert a horizontal rule. If a 3 or 6 digit (or named) color code is specified after the # the rule will be colorized [#xxx]..[/#] or [#xxxxxx]..[/#] Use a 3 or 6 digit hex code to colorize the text between the markers [img]..[/img] Insert an image. The full URL of the image goes between the markers. You can include HTML attributes to be applied to the img tag in the opening marker (ie, [img width=128 height=128]
)[button]caption::action[/button] Create a button with the label "caption" that performs the action defined by "action". By default, buttons will be colored according the the buttontextcolor and buttonbackground card settings. You can optionally color individual buttons by specifying a text color and a background color as part of the [button] command (ie, [button:#ffffff:#000000] will create a button with white text on a black background. In order to set a background color, the foreground color must be specified. [sheetbutton]caption::character::abilityname[/sheetbutton] Create a button that, when pressed, will run the "abilityname" macro on the "character" charactersheet. Useful for launching macros from a macro mule character sheet. By default, buttons will be colored according the the buttontextcolor and buttonbackground card settings. You can optionally color individual buttons by specifying a text color and a background color as part of the [sheetbutton] command (ie, [sheetbutton:#ffffff:#000000] will create a button with white text on a black background. In order to set a background color, the foreground color must be specified. [rbutton]Caption::ReentryLabel;Parameter[/rbutton] Create a reentrant button which, when clicked by the user, will resume script execution at "ReentryLabel", passing "Parameter" to the [&reentryval] string variable. By default, buttons will be colored according the the buttontextcolor and buttonbackground card settings. You can optionally color individual buttons by specifying a text color and a background color as part of the [rbutton] command (ie, [rbutton:#ffffff:#000000] will create a button with white text on a black background. In order to set a background color, the foreground color must be specified. [t] Converted to HTML table tag. Text after the "t" will be included inside the tag (width, border, etc) [/t] Converted to HTML close table tag. [tr] Converted to HTML table row tag. Text after the "tr" will be included inside the tag [/tr] Converted to HTML close table row tag. [td] Converted to HTML table cell tag. Text after the "td" will be included inside the tag [/td] Converted to HTML close table cell tag.
Code Example
Variables
See the Referencing-section for information on referencing variable content
ScriptCards supports two types of variables : Roll Variables and String Variables. Either type can be used in a conditional statement, or use to substitute their value into the tag or content portion of other statements. For both types of variables, variable names are case sensitive. While it is possible to assign both a string and a roll variable the same name, doing so will likely result in confusion when looking at the script later, so it is not recommended.
Roll Variable and String variables are completely separate internally, so it is possible to use the same name for both a Roll Variable and a String, but this can become confusing and is not an encouraged practice.
Roll Variables
A roll variable is used to store the results of dice rolls or math calculations when more than just the final resultant value is important. Roll Variables are set via the {{{1}}}
statement or the {{{1}}}
referencing structure, and are processed by the ScriptCards roll parser.
--=AttackRoll|1d20 + @{selected|strength_mod} [STR] + @{selected|pb} [PROF] --+Result|[$AttackRoll]
In this case, we are creating a roll variable called AttackRoll. The content portion of the roll will be passed to the ScriptCards roll processor, which will roll 1d20 and add two modifiers, storing the result in the AttackRoll variable. The roll parser will store extra information about the roll to various components of the AttackRoll variable, including the text passed to the parser, a formatted version of the result in a hover-over text box, and details on each die rolled.
A Roll Variable is referenced using the [$variablename]
structure. See the Referencing-section for all of the additional information retrievable from a Roll Variable.
String Variables
String Variables are assigned with the --&
statement and are referenced using [&variableName]
notation. A string variable can contain just about any text, however there are some character sequences that will be misinterpreted by the Roll20 chat server. In that case, it is necessary to build the string variable in multiple pieces. This trick can also be useful when you want to use some character sequences in strings our output that would be clobbered by the chat server {{c|[[}} for example, which the chat server will interpret as an inline roll.
This can be accomplished by splitting the string into pieces during its creation. For example:
--&QB|? --&QB|+{ --&QE|} --&AB|@ --&AB|+{ --&TB|& --&TB|+# --&TB|+64 --&TB|+; --&TB|+{ --&BED|& --&BED|+# --&BED|+128719; --&CLOCK|& --&CLOCK|+# --&CLOCK|+128336; --&SPACE|X X --&SPACE|[&SPACE(1,1)] --&obrac|[ --&cbrac|]
The code above defines several string that are generally useful in scripts. &QB (build in two parts, ?
and {
can be used to initiate a roll query as part of a button without the chat server asking the question when the overall script is run. &AB is similarly used for attribute references, while &TB shows an example of escaping an HTML sequence that would be replaced by the chat server incorrectly.
The &BED and &CLOCK strings use HTML escaping to assign emojis to strings, while &SPACE uses a substring reference to create a variable that just includes a space (since a space at the end of a line, including a variable assignment will be stripped out by the parser). Finally, &obrac and &cbrac are opening and closing brackets to allow for {{c|[[}} type structures.
Predefined String Variables
There are a handful of variables assigned automatically when a ScriptCard is executed that can be used in your script to retrieve information about some game conditions when the script was executed:
Variable Value SendingPlayerID Contains the object ID of the player that sent the macro SendingPlayerName Contains the display name of the player SendingPlayerColor Contains the color code associated with the player SendingPlayerSpeakingAs The contents of the "Speaking As" dropdown window SendingPlayerIsGM Contains 1 if the player is a GM, and 0 if the player is NOT a GM
Arrays
Originally only usable with the --~ (function) command, arrays have been expanded and revamped to make them a more integrated part of the ScriptCards language. The information below has been updated to be current with the 2.1.12 release of ScriptCards available on the GitHub repository and will be included in the next pushy to OneClick
An **Array** is a collection of string variables that are all associated with the same variable name and retrievable/settable by an index number into the array. For example, the following ScriptCards code can be used to create a simple array called Fruits that contains 4 elements:
--~|array;define;Fruits;Banana;Mango;Pineapple;Watermelon
Alternatively, an array can be created by directly assigning strings to array element references:
--&Fruits(0)|Banana --&Fruits(1)|Mango --&Fruits(2)|Pineapple --&Fruits(3)|Watermelon
Functionally, these two blocks of code are identical and both results in the creation of a four element array called Fruits.
Array indexes start at 0
Adding Elements to an Existing Array
You can use the --& command to add elements to an array, even if you don't know the size of the array. If you specify an index number that already exists in the array, that element will be replaced, but if you specify an index number larger than the last index in the array, the element will be added to the end of the array at the next available index. For example,--&Fruits(9999)|Papaya
will add Papaya as element 4 of the array, since that is the next available index number.
A more proper method, however, would be to use the length of the array to ensure that you will always use an index higher than the highest index:--&Fruits([@Fruits()])|Papaya
functions identically, but will not break if your array already has 9999 items in it. See the Array Metadata section below for details on the @[ArrayName()] construct.
You can also add elements to the beginning of the array by specifying a negative index: --&Fruits(-1)|Lemon
will insert Lemon as element 0 and push all of the exiting elements down one index, so element 1 will become Banana, 2 Mango, etc.
Referencing Array Elements
When you wish to retrieve the value stored in array element, you can reference that element with the pattern [@ArrayName(index)]. For example: <code>[@Fruits(2)]
given the array defined above, will return "Pineapple" in place of the variable reference.
Array Metadata
Some additional information about arrays is available using specialized element notation:
[@Array()]
or [@Array(length)]
will return the number of items in the array. Note that the number returned will always be one larger than the maximum index of the array since indexes start at 0.
[@Array(maxindex)]
or [@Array(lastindex)]
will return the index number of the last item in the array.
Note that using the length property will allow you to always add elements to the end of an array:
--&Fruits([@Fruits(length)])|Papaya
will add Papaya to the Fruits array at the end of the array.
Changing Array Element Values
The same syntax used to assign array elements can be used to update the element values. Given the array defined above, --&Fruits(2)|Grape
will change the Pineapple element (in Index position 2) to Grape.
Traversing Arrays The easiest method to traverse an array is to use the --% looping structure with the foreach modifier:
--%loop|foreach;Fruits --+Fruit|[&loop] --%|
The code above will traverse each element in the Fruits array and print the value. It could also be written using a normal for loop and index numbers:
--%loop|0;[@Fruits(maxindes)] --+Fruit|[@Fruits([&loop])] --%|
In this case the difference is that in the foreach structure, the loop variable is actually assigned the value of the element, while in the normal loop the loop variable is assigned the index number which then needs to be supplied to the [@Array(index)] structure to retrieve the element.
Additional information on looping is available in the --% loop command documentation.
Special Array Functions
There are a number of special options for the --~ (function) command that can be used to generate arrays based on information stored in Roll20. These are listed in the function table above under the array category, and include things like creating an array of all of the tokens on a page, or the entries in a repeating section on a character sheet. They are also functions to sort and otherwise manipulate the array (replacing elements, for example). Finally there are legacy functions (such as getfirst, getnext, getindex an the like) that were used for traversing arrays and iterating through the elements. While these still work, the ScriptCards language has evolved to make working with arrays quite a bit simpler using loops and array referencing.
NOTE: The documentation below remains for legacy array usage. It is still supported and will still work, but is not the currently preferred method
Each array keeps track of an internal index position (starting at 0). Several commands let you manage this index:
- getindex returns the current index value
- setindex sets the index to the specified location in the array
- getlength returns the number of elements in the array
- indexof returns the index location of the specified element
Other commands let you retrieve values from the array:
- getfirst sets the index to 0 and returns the value at that position
- getnext advances the index by 1 and returns the new current value
- getprevious reduces the index by 1 and returns the new current value
- getlast sets the index to the last elements in the array and returns the new current value
If/when you hit the end of the array, you will get a return value of ArrayError
, which can be used to detect the end of the array when looping through by index. See Referencing Array Elements below for additional information.
Manipulating Array Elements
Several array commands deal with inserting, removing, and modifying elements:
- add works just like define, except that it takes an existing array and adds elements to it based on the passed parameters
- remove looks for items matching each passed parameter and removes them from the indicated array if they exist
- removeat allows you to specify an index location in the array and remove the element at that position
- replace searches an array for a value and replaces all occurrences of it with a new value (if found)
- sort sorts the elements in the array in ascending order
- stringify returns a string variable that includes each array element separated by the default semicolon (
;
) or (new in 1.6.7) the current#parameterdelimeter
Referencing Array Elements
You can either use the index (getfirst
, getnext
, etc.) to traverse an array and work with the values, or you can use (new in 1.3.1) direct array element referencing.
!script {{ --~dummy|array;pagetokens;myarray;@{selected|token_id} --~count|array;getcount;myarray --+Total:|There are [&count] graphical objects on the page --~testvar|array;getfirst;myarray --:loop| --+Value|[*[&testvar]:character_name] --~testvar|array;getnext;myarray --?[&testvar] -ne ArrayError|loop --+Loop1|Is Done! }}
This example defines an array based on the tokens on the page and then loops through them, starting with a getfirst
, displaying the character name, and using getnext
until the result is ArrayError
, at which point the loop exits. Here is the same routine, except it uses a For...Next loop and direct array referencing:
!script {{ --~dummy|array;pagetokens;myarray;@{selected|token_id} --~count|array;getcount;myarray --+Total:|There are [&count] graphical objects on the page --%loopCounter|1;[&count] --+Value|[*[@myarray([&loopCounter])]:character_name] --%| --+Loop|Is Done! }}
This line : --+Value|[*[@myarray([&loopCounter])]:character_name]
uses [@arrayName(index)]
format (inside a [*characterid:attribute]
syntax) to perform the same task as running through the loop with the index.
Predefined Arrays
As with string variables, there is an array created automatically by ScriptCards when a script executes if there are tokens selected in the VTT.
Array Value SC_SelectedTokens Array containing the Token IDs of any tokens selected by the user when the script is executed
Looping Structures
ScriptCards supports four types of looping structures, all using the --%
statement.
For...Next Loops
A For...Next loop allows you to run a series of commands an arbitrary number of times, with a variable counting each iteration.
--%LoopCounter|<start>;<end>;[step]
The start and end values are required, while the step parameter is optional. If the step is omitted, it will be assumed to be 1
. A string variable named after the line tag (LoopCounter
in the case above) will be created and will hold the current iteration value for the loop. Here is a real example:
--%LoopCounter|1;10;1
This will begin a loop identified by LoopCounter
that will start at 1, increasing by 1 each iteration (the step) until it has completed 10 executions.
The "next" statement is simply --%|
, with no tag or parameters. This indicates to ScriptCards that it should increment the counter and go back to the beginning of the loop. Extending the example above:
!script {{ --%LoopCounter|1;10;1 --=Roll|1d20 --+Loop|Counter is [&LoopCounter], roll was [$Roll] --%| }}
The --%!|
sequence will break out of the loop, no matter how many iterations are remaining.
The %
and %!
character sequences can also be used as part of conditional statement to indicate to ScriptCards that it should continue (%) or break (%!) the loop:
--?"X[&RollInfo]X" -eq "XX"|%
In this example, if the string variable RollInfo
is empty, the loop will return to the top and continue with the next iteration, while:
--?"X[&RollInfo]X" -eq "XX"|%!
Would cause the whole loop to end if the condition were true.
While Loops
A while loop allows you to continue executing a series of statements while a given conditional statement evaluates to true.
--%loop|<until>;<conditional>;[step]
If the conditional is true, the loop will be executed until the conditional becomes false. If the conditional is false to begin with, the loop will not execute at all. The loop counter variable has no useful meaning for While loops.
!script {{ --=Iteration|0 --&MyString|[=1d10 - 1] --%loop|while;[&MyString(length)] -lt 12 --=Iteration|[$Iteration] + 1 --+Iteration [$Iteration.Raw]|[&MyString] --&MyString|[&MyString][=1d10 - 1] --%| --+Final|[&MyString], [&MyString(length)] }}
The example above will generate a 12 digit number by starting with a string (&MyString) with a length of 1, and adding a digit each time through the loop while there are less than 12 digits in the string.
Until Loops
Very similar to While loops, until loops check their conditional after each iteration, including the first.
!script {{ --=Iteration|0 --&MyString|[=1d10 - 1] --%loop|until;[&MyString(length)] -ge 12 --=Iteration|[$Iteration] + 1 --+Iteration [$Iteration.Raw]|[&MyString] --&MyString|[&MyString][=1d10 - 1] --%| --+Final|[&MyString], [&MyString(length)] }}
Just as in the While example, this loop will create a 12 digit number. Nowever, if &MyString already contained a 12 digit number, and additional digit would be added since the loop will always run at least once.
For Each Loops
The final type of looping structure is only used with arrays, and is called a For Each loop. A For Each loop will be run once for each item in the array, and the loop control variable will be set to the value of the array element that is currently being processed.
!script {{ --~|array;fromrepeatingsection;Attacks;@{selected|character_id};repeating_attack;atkname --%loop|foreach;Attacks --+Attack|[&loop] --%| }}
This code creates an array based on the "repeating_attack" repeating section's atkname field (in this case, from the 5E character sheet). It then loops for each entry in the array and displays the name of the attack.
Referencing
Referencing Overview
Referencing allows you to substitute the values of variables, objects, attributes, settings, and the like someplace in a ScriptCards line. The table below gives an overview of the various referencing modes and what each one means. In general, references are enclosed in square brackets ([
and ]
) and begin with a character indicating what kind of reference it is (such as $
or &
), followed by a descriptor that indicates where the value should come from.
Character Type Example Notes $ Roll Variable [$AttackRoll] Roll variables support a number of modifiers (ie, [$AttackRoll.Base]
). See the Roll Variables section below for details& String Variable [&PlayerName] See expanded string referencing below * Object Attributes [*S:character_name] See Attribute Referencing in the next table for details. % Subroutine Parameters [%1%] Only available when a subroutine is called with a -->
or similar construct. Parameters are numbered beginning at 1.@ Array Elements [@Colors(5)] The name of the array follows the @
symbol. The index (zero-based) is in parenthesis after the name.~ Card Settings [~title] Returns the value of the ScriptCards settings (set via --#
lines) (1.6.5+)= Inline Rolls [=1d20] or [=Result:1d20] Rolls the die format specified at the time the reference is processed. If a name followed by a colon proceeds the roll specifier, the result of the roll will be saved to the named roll variable. The replacement value of the inline roll will be the raw roll value (same as .Raw when referencing a roll variable). Square brackets for flavor text are not supported inside inline rolls, and + an - are the only currently supported component separators (ie, 1d20 + 5 (STR) is fine, but 1d20 * 2 [Something] is not supported both because of the multiplication and because of the embedded square brackets.
Expanded String Referencing
ScriptCards 2.1.7+ expands the syntax used to reference strings by including inline functions for things like substrings, find and replace, etc. None of these functions modify the original string variable.``` They simply return a string with the function applied.
Example Notes [&MyString] = "The quick Brown Fox jumps over the Lazy Dog" Basic string referencing [&MyString(length)] = 43 Returns the number of characters in the string [&MyString(tolowercase)] = "the quick brown fox jumps over the lazy dog" Returns the string in all lower case [&MyString(touppercase)] = "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG" Returns the substring in all upper case [&MyString(totitlecase)] = "The Quick Brown Fox Jumps Over The Lazy Dog" Returns the string in Title case (first letter of every word capitalized) [&MyString(replace,quick,fast)] = "The fast Brown Fox jumps over the Lazy Dog" Returns a string with the first occurance of the second parameter with the third [&MyString(replaceall,o,i)] = "The fast Briwn Fix jumps iver the Lazy Dig" Returns a string with all occurances of the second parameter with the third [&MyString(contains,Dog)] = 1 <-- Case sensitive contains Returns 1 if the string contains the search text, or 0 if it does not (Case sensitive) [&MyString(icontains,dog)] = 1 <-- Non-Case Sensitive contains Returns 1 if the string contains the search text, or 0 if it does not (Case insensitive) [&MyString(indexof,Jumps)] = -1 <-- Case sensitive indexof - indexof returns -1 if not found Returns the first position of the search string in the string, or -1 if it does not exist. Case sensitive [&MyString(iindexof,jumps)] = 20 <-- Non-case sensitive indexof. First location where the sequence occurs Returns the first position of the search string in the string, or -1 if it does not exist. Case insensitive [&MyString(lastindexof,o)] = 41 <-- The character position (0-based) of the last time the sequence occurs Returns the first position of the search string in the string, or -1 if it does not exist. Case sensitive. [&MyString(lastindexof,o)] = 41 <-- The character position (0-based) of the last time the sequence occurs Returns the first position of the search string in the string, or -1 if it does not exist. Case insensitive. [&MyString(4)] = "Quick Brown Fox Jumps Over the Lazy Dog" <-- Starting at char #4, rest of string Return a substring starting at character 4 and returning the rest of the string [&MyString(4,5)] = "Quick" <-- 5 characters beginning at character 4 Return a substring 5 characters long, beginning at position 4 [&MyString(-3)] = "Dog" <-- The last 3 characters of the string Return a substring starting 3 characters before the end of the string [&MyString(-8,4)] = "Lazy" <-- Starting 8 characters from the end of the string, 4 characters Return a substring 4 characters long, starting 8 characters before the end of the string.
Object Attribute Referencing
All object attribute referencing use the *
prefix character, with the second (and sometimes third) character providing context).
Prefix Example Notes *S: [*S:character_name] Returns token or character attributes for the token/character specified for the sourcetoken
setting. Token attributes are prefixed witht-
(ex:[*S:t-bar3_value]
).*T: [*T:character_name] Returns token or character attributes for the token/character specified for the targettoken
setting. Token attributes are prefixed witht-
(ex:[*T:t-bar3_value]
).*id: [*-lkfne34mda4:character_name] when *
is followed by an ID, the token/character will be queried for the attribute value requested.*C: [*C:playerpage] Returns campaign attributes. *P: [*P:showgrid] Returns page attributes. If an activepage
setting has been set, theactivepage
will be referenced. If not, the currentplayerpage
(where the ribbon is) for the campaign is referenced.*R: [*R:atkname] Used with --R
(Repeating Section) commands to return the VALUE of the current repeating row item's attribute by name.*R> [*R>atkname] Used with --R
(repeating section) commands to return the full attribute name for a repeating row attribute.*O: [*O:-lkfne34mda4:character:name] Return a property reference for any property on an object with a known ID and type. The syntax is [*O:ObjectID:ObjectType:PropertyName]. The object types match Roll20's object definition and are campaign, player, page, path, text, graphic, character, attribute, ability, handout, macro, rollabletable, tableitem, deck, card, hand, jukeboxtrack, custfx Version 2.1.0
Nested References
Reference syntax can be nested, and will be resolved from inside to outside. For example, given a roll variable MishapRoll
, and a series of strings (Mishap1
, Mishap2
, Mishap3
, Mishap4
), the following reference will begin by substituting [$MishapRoll.Raw]
for the roll's numeric value, and then replace the resulting MishapX
string with its value:
[&Mishap[$MishapRoll.Raw]]
Roll Variables
Roll Variables can be referenced from the content portion of any line type, and from the tag portion of conditional statements. The referenced value is replaced when the line is executed.
There are several modifiers that can be used to reference parts of a roll:
Modifier Meaning No modifier In a Direct Output Line (--+), GM Output Line (--*), or String Assignement (--&), will be replaced with a formatted roll display, including a mouseover with roll text details. In any other type of line, will display the same results as .Raw .Total The end result of the roll equation. Formatting rules for "No Modifier" apply based on line type. .Raw The total value of the roll variable without any formatting, no matter what kind of line the reference is used in. .Base The cumulative result of any dice rolled in the Roll Text (Numeric modifiers are not included) .Ones The number of dice in the roll that came up as 1s .Aces The number of dice in the roll that came up as the maximum number on the die .Odds The number of dice in the roll that came up with an odd number .Evens The number of dice in the roll that came up with an even number .RollText The raw text of the roll that was use to generate the results .Text A text representation of the results of the roll, including the numbers rolled for each die .tableEntryText The text portion of the result of a table roll .tableEntryImgURL The image source portion of the result of a table roll .tableEntryValue If the tableEntryText is purely numeric, will contain the numeric value
String Variables
To reference a string variable, use the notation [&variablename]
. String variables can be referenced in direct output, roll variable assignment, and string variable assignment statements.
Character/Token Attributes
A character or token attribute can be referenced from content portion of any type of line and is substituted when the line is executed. The general format for referencing a character attribute is [*ID:attribute]
. ID can be a token ID or a character ID (these start with a dash). Additionally if you have specified a sourceToken or targetToken, you can substitute "S" or "T" for the ID (for example [*S:npc_type]
will retrieve the npc_type
attribute from the source token.
By default, all attribute references will be pulled from the character object that the ID represents (either directly or by being a Token ID that represents a character).
Keep in mind, that if you want to access the "max" of a character attribute (for example, the max hit points), then you cannot trust the name that your roll20 character sheet shows you when you hover your mouse over the max hit points. For example, this reference will not work: [*S:hp_max]
. Instead, you need to use this reference: [*S:hp^]
.
If your ID refers to a token, token attributes can be accessed by preceding the attribute name with t-
, for example [*S:t-aura1_radius]
. Supported token attributes are:
(NOTE: As of version 1.6.1 of ScriptCards, the below list is no longer a limitation on the token attributes you can reference. All token attributes available in Roll20 can now be accessed and the need to update the internal list as new attributes are added has been eliminated.)
t-name | t-id | t-statusmarkers | t-bar1_value |
t-bar1_max | t-bar2_value | t-bar2_max | t-bar3_value |
t-bar3_max | t-top | t-left | t-width |
t-height | t-rotation | t-layer | t-aura1_radius |
t-aura1_color | t-aura2_radius | t-aura2_color | t-aura1_square |
t-aura2_square | t-tint_color | t-light_radius | t-light_dimradius |
t-light_angle | t-light_losangle | t-light_multiplier | t-light_otherplayers |
t-light_hassight | t-flipv | t-fliph | t-controlledby |
t-_cardid | t-_pageid | t-imgsrc | t-bar1_link |
t-bar2_link | t-bar3_link | t-represents | t-layer |
t-isdrawing | t-name | t-gmnotes | t-showname |
t-showplayers_name | t-showplayers_bar1 | t-showplayers_bar2 | t-showplayers_bar3 |
t-showplayers_aura1 | t-showplayers_aura2 | t-playersedit_name | t-playersedit_bar1 |
t-playersedit_bar2 | t-playersedit_bar3 | t-playersedit_aura1 | t-playersedit_aura2 |
t-lastmove | t-adv_fow_view_distance | t-has_bright_light_vision | t-has_night_vision |
t-night_vision_distance | t-emits_bright_light | t-bright_light_distance | t-emits_low_light |
t-low_light_distance | t-has_limit_field_of_vision | t-limit_field_of_vision_center | t-limit_field_of_vision_total |
t-has_limit_field_of_night_vision | t-limit_field_of_night_vision_center | t-limit_field_of_night_vision_total | t-has_directional_bright_light |
t-directional_bright_light_center | t-directional_bright_light_total | t-has_directional_dim_light | t-directional_dim_light_center |
t-directional_dim_light_total | t-lightColor | t-tooltip |
It is important to note that some attributes names on tokens have corresponding attribute names on characters, which represent different values. For example, [*T:id]
returns the character ID, while [*T:t-id]
returns the token ID.
Subroutine Parameters
When using a gosub statement (-->
) or a conditional marked as a gosub (prefixing the label with a >
character), you can pass any number of parameters separated by semicolons (;
) that the code in the subroutine can utilize.
Subroutine parameters are numbered starting at 1, and are accessed by using the notation [%number%]
, so the first parameter is [%1%]
, the second is [%2%]
, etc.
Parameter substitution happens on all line types, and happens prior to character attribute references or roll variable substitution.
Campaign Attribute
You can retrieve properties of the API's Campaign object with the [*C:attributename]
syntax. For example, [*C:playerpageid]
will retrieve the current player ribbon page from the Campaign object.
Page Attributes
If you have set the activepage
parameter, you can retrieve page-related properties with the [*P:attributename]
syntax, including the page's UDL parameters.
Repeating Section Values
You can reference repeating attribute data using the syntax [*R:attributename]
syntax (similar to referencing standard character attributes). The currently active repeating row information will be used to retrieve attribute values. You can also retrieve the full attribute name for a repeating row attribute by using the [*R>attributename]
notation. This is useful to pass to things like chatsetattr.
See the section named Repeating Section Access for more information.
Array Elements
After an array has been declared, the elements can be referenced with [@arrayName(index)]
. Array indices start at 0.
ScriptCards Settings
It is now possible to reference ScriptCards settings (set with the --#
command) using the [~settingname] syntax (ie, [~title]
will be replaced with the title setting at the time the reference is interpreted.
Deferred Resolution for Meta Scripts
API:Meta-Toolbox
APIs to patch other API commands
Meta-Toolbox Scripts
created by Timmaugh
Related APIs
As of 1.2.9, ScriptCards supports a deferral character for use when calling another API script with via the --@
statement, to defer processing of meta script references so they get processed prior to the sub-API call instead of prior to ScriptCards execution. To defer this processing for meta script (SelectManager, Fetch) by inserting a deferral character into the meta call. For example, if I want to have ScriptCards call TokenMod as if the token for "Quej Gr'stra" (yes, I let Roll20 name my test NPCs) I could use something like this:
--@token-mod|{^& select Quej Gr'stra} _on showname
The ^
in between {
and &
will prevent SelectManager from seeing the call when the ScriptCard script is processed, but the --@
statement will remove the deferral character so the command that will be sent by ScriptCards is:
!token-mod {& select Quej Gr'stra} --on showname
With the deferral character removed, SelectManager will see the {& select ...}
and do its magic.
While the default deferral character is ^
, the deferral character is a setting that can be changed:
--#deferralcharacter|%
Will make %
the deferral character for future --@
statements in the running script.
Supported Meta Script structures:
-
{^&...}
- for SelectManager -
@^(...)
and*^(...)
for Fetch -
get^.
andset^.
for Muler ( v 1.4.5+ )
Arrays
Arrays are a new data type introduced in version 1.1.12 of ScriptCards, and are manipulated with associated function (--~) commands.
- Arrays are a lists of strings. Items in an array cannot contain the semi-colon (
;
) character, as that is used to separate parameters in the function code that deals with arrays. - Arrays are accessed via the
--~
script command. In some cases, the value of the tag (variable name) for array commands is not used, and can be a dummy value or simply omitted. I have omitted them in the statements below. - All commands that DO return a value return string values, even if the content is numeric.
- If a command returns a value and there is some sort of reason that it isn't an array value, you will get "ArrayError" in the return value. This can happen if you reach the end of an array while stepping through it, for example, so checking for "ArrayError" can serve as the end condition for a loop.
- Each array keeps track of its current index, allowing you to step forward and backwards through arrays.
- Any number of arrays can be defined.
- Unlike string variables and roll variables, array variables cannot (currently) be referenced directly. It is necessary to use the function (
--~
) syntax to manipulate arrays and get values from them as strings for use in other parts of your script.
Interacting with the GM and Players
There are some severe limitations to what can be accomplished with the Roll20 API, and many of those limitations revolve around user interactivity. While the API can interact with objects in the campaign and generate output to the game chat window, it has exactly zero access to the user interface. You can't pop up a dialog box to get information from a player or prompt the someone to pick X number of targets, where X is only determined after your script has done some processing.
Method 1: The Information Request (--i) Command
While it is certainly possible to use roll queries to fake something similar to the above, the limitations here will soon become obvious when trying to do anything even a little complicated. This is because all roll query questions are asked of the user BEFORE the script is sent to the API for processing, meaning if you include a roll query in your code, even in a place that is completely inaccessible by the ScriptCards code, the user will still be prompted to input values for it. Consider this example:
!script {{ --=Roll|1d4 --?[$Roll.Raw] -eq 4|>RandomEncounter|>AllQuiet --X| --:AllQuiet| --+It's quiet...|Too quiet... --<| --:RandomEncounter| --+Random Encounter!|A group of ?{How many bugbears?|1|2|3|4|5|6|7} bugbears jump from the woods and attack! --<| }}
What we really want to happen here is the random encounter roll to take place and only be asked to supply a number of bugbears if we rolled a 4. Unfortunately, because the chat server pre-processes the API command, the bugbears question will always be asked before anything else processes.
Getting around this limitation requires some creative thinking and a bit of extra work. Let's stick with the same simple random encounter concept but mix things up a bit.
!script {{ --=Roll|1d4 --?[$Roll.Raw] -eq 4|>RandomEncounter|>AllQuiet --X| --:AllQuiet| --+It's quiet...|Too quiet... --<| --:RandomEncounter| --iA Random Encounter has occurred and we need more information to continue;Click to provide details|q;bugbearcount;How many bugbears|1|2|3|4|5|6|7 --+Random Encounter!|A group of [&bugbearcount] bugbears jump from the woods and attack! --<| }}
This time, we won't be prompted for a number of bugbears unless a random encounter comes up on the 1d4. If it does, the script will pause execution and whisper the player running the script a message. The message will explain that additional information is needed, and provide a button for the player to click to answer the bugbear question. After they do, execution will be resumed on the following line with the new information in place.
In this case, the q;bugbearcount;How many bugbears|1|2|3|4|5|6|7
portion of the code is the encoded question:
q
- meaning we are going to generate a Querybugbearcount
- The string variable our result will be stored in when execution resumesHow many bugbears|1|2|3|4|5|6|7
- This is the exact same roll query text above, without the surrounding?{
and}
structure.
The --i
command can ask for multiple pieces of information, including targets and roll query responses. Requesting the player select a target would look something like:
t;detectingCharacter;Which character detects the bugbears?
In this case:
t
- inidcates that we want the player to select a target tokendetectingCharacter
- the string variable that will store the token ID of the selected tokenWhich character detects the bugbears?
- The prompt that the target selection box will display
Any combination of t
and q
information can be included in the same --i
command by separating the components with double vertical bars:
--iA Random Encounter has occurred and we need more information to continue;Click to provide details|q;bugbearcount;How many bugbears|1|2|3|4|5|6|7||t;detectingCharacter;Which character detects the bugbears?
would ask for a number of bugbears and for the player to select which character saw them coming.
Method 2: Buttons
Roll20's chat server has a built-in method for creating buttons in chat:
[Attack Roll](!attackroll)
which will create a button labeled "Attack Roll" that executes the !attackroll
API command when the user clicks it. This is a fairly basic API button, and ScriptCards supports creation of buttons in --+
and --*
output lines with the following syntax: [button]caption::action[/button]
, so the same button above could be created in ScriptCards with:
[button]Attack Roll::!attackroll[/button]
Things get a bit more tricky if you want to execute a macro as the result of clicking a button. You would think:
[Attack Roll](#attackmacro) or [button]Attack Roll::#attackmacro[/button] would work, but it just won't do anything at all when clicked. In order to execute a macro from a Roll20 button, you need to prefix it with !
#
, which translates to an exclamation point (!
) so Roll20 thinks it is an API call, followed by a carriage return (
) followed by the pound sign (#
) that prefixes macro names: NOTE: copying the above string from the wiki will result in non-printing characters being inserted into your macro because the Wiki can't display the string sequence above without them inserted into it. You will need to manually type the unicode character information (beginning at the ! and ending at the second #) into your macro.
[Attack Roll](!
#attackmacro) or [button]Attack Roll::!
#attackmacro[/button] will produce a button that executes the #attackmacro
macro when clicked.
There is another button syntax that can be used with ScriptCards to make calling ability macros stored on a character sheet a bit easier. The following syntax:
[sheetbutton]caption::character::ability[/sheetbutton]
will look on the indicated character's sheet for a matching ability name and create a button that will execute it when clicked. The character parameter can be a character ID, a token ID, or a character name and ScriptCards will do its best to find a match.
[sheetbutton]Fireball::Spell_Mule::Fireball[/sheetbutton]
Will look for an ability named "Fireball" on a character named "Spell_Mule" and execute it when clicked. There is no need to specify the !
#
prefix when creation buttons with [sheetbutton]
Finally, a third type of button is available : [rbutton]
. These buttons are used for reentrant scripts.
Button Colors
By default, the buttons ScriptCards will follow the color scheme from Roll20, resulting in pink buttons with white text on them. You can include hex color codes in the [button]
and [sheetbutton]
markers to change the colors associated with an individual button:
[button:#ffffff:#000000]Attack Roll::!attackroll[/button]
will create a button with white text (#ffffff
) on a black background (#000000
). It is possible to only specify a text color (the first color parameter) without the second, but to set the background color of the button you must also set the text color as well.
Alternatively, you can set the buttontextcolor
and buttonbackground
settings to change the color of all buttons the script creates from that point forward (see the --#
command).
Reentrant Scripts
Reentrant scripts allow you to create buttons in your script code that will re-execute the script at a given label within the code. If you set the reentrant setting (--#reentrant|somevalue
) to a non-zero value, your setting and variable information will be preserved between executions. Reentrant script can be used to present menus or choices and then continue acting.
Important: The value of the reentrant setting will be used to identify the appropriate script to resume when reentrancy is used. If more than one character can potentially run the same script at the same time, it is a good practice to include the character ID in the reentrant setting in order to maintain a separate list of variables. Something like:
--#reentrant|My Cool Script @{selected|character_id}
Reentrant buttons are created with the [rbutton]Caption::ReentryLabel;Parameter[/rbutton]
construct. The caption will be displayed on the generated button. ReentryLabel
is the name of a label in your script that the button will jump to when clicked, and Parameter will be passed in as a string value called reentryval
.
Example:
!script {{ --#reentrant|testing --=Roll|1d20 --+Roll|[$Roll] --&String|That was a [$Roll.Raw]! --~x|array;define;MyArray;Apple;Banana;Orange --+Try it|[rbutton]Hello!::EXEC_PC_SPELL;9[/rbutton] --X| --:EXEC_PC_SPELL| --+ReentryVal|[&reentryval] --+The value of Roll is|[$Roll] --+Value of String|[&String] --+Array|[@MyArray(0)] --X| }}
This script sets up some variables and then displays a button labeled "Hello!". If the user clicks the button, the script will be re-entered starting at EXEC_PC_SPELL
, which will display the content of the variables from the original execution.
Note: This section needs to be expanded upon
Libraries
You can now create handouts in your game in Roll 20 with the name format ScriptCards Library NAME
, where NAME
is a name you assign to the library. Library names are case sensitive. It is my hope that the more proficient ScriptCards scripters out there will provide procedure libraries (or procedures that can be included in libraries) for others to use to make their scripting life easier. Be they specific to a game system, or to a type of activity, I think a robust set of libraries that GMs could use to enhance their scripting capabilities would be very valuable to the community. Should such things begin to emerge, I’ll create a portion of the ScriptCards Wiki page to house them.
To include one or more libraries in a script, use the +++libname+++
directive (does not need a --
line associated with it). Multiple library names can be specified by separating them with semicolons (i.e., +++General;dnd5elib;Colorize+++
would include three libraries (General, dnd5elib, and Colorize).
Included libraries are separated from the main script code by the automatic inclusion of --X|
before the first library is appended to the script, and all libraries are loaded at the end of the script before script processing takes place.
Procedures and labels in libraries can be used just as if they were included in the body of your script. Note that this DOES mean that you could, technically, jump into a library with a direct branch --^
or direct branch conditional, but I recommend using libraries to store reusable procedures.
The Notes section of the library handout stores the library code, and is written just like any other ScriptCards code except:
- They cannot use roll queries (
?{Some Prompt:}
) to get information from the user at execution time. - They cannot use
@{}
notation to access character and token information.
Both of these limitation stem from the fact that Procedure Libraries are not processed by the chat server, which is what handles these items.
Here is an example of handling damage modifications (resistance, vulnerability, and immunity) in D&D 5E by Roll20!script {{ +++dnd5elib+++ --#|Damage Modifiers Test --#targettoken|@{target|token_id} -->Lib5E_CheckDamageModifiers|ResistType;fire --=DamageRoll|2d10 [&ResistType] --+Test:|[$DamageRoll] fire damage -->Lib5E_CheckDamageModifiers|ResistType;cold --=DamageRoll|2d10 [&ResistType] --+Test:|[$DamageRoll] cold damage -->Lib5E_CheckDamageModifiers|ResistType;poison --=DamageRoll|2d10 [&ResistType] --+Test:|[$DamageRoll] poison damage -->Lib5E_CheckDamageModifiers|ResistType;acid --=DamageRoll|2d10 [&ResistType] --+Test:|[$DamageRoll] acid damage --X| }}
Library content (In a handout called “ScriptCards Library dnd5elib” NOTE: Paste into Notepad first and then paste into the handout in Roll20 to avoid bringing over HTML formatting from the web site):
--/|ScriptCards Library: dnd5elib version 0.0.1 --/|Provides various utility procedures for D&D 5E games --/|Lib5E_CheckDamageModifiers handle damage resistance, vulnerability, and immunity. --/|Pass a string variable to be filled with a string to be appended to a dice roll and the damage type --:Lib5E_CheckDamageModifiers|damageVariableName;damageType --&[%1%]| --?"[*T:npc_vulnerabilities]" -inc "[%2%]"|>_Lib5E_IsVulnerable;[%1%] --?"[*T:npc_resistances]" -inc "[%2%]"|>_Lib5E_IsResistant;[%1%] --?"[*T:npc_immunities]" -inc "[%2%]"|>_Lib5E_IsImmune;[%1%] --<| --:_Lib5E_IsVulnerable| --&[%1%]| * 2 [Vulnerable] --<| --:_Lib5E_IsResistant| --&[%1%]| \ 2 [Resistant] --<| --:_Lib5E_IsImmune| --&[%1%]| * 0 [Immune] --<|
The idea is that the functions in the library create a string that can be appended to a roll to modify the output based on resistances, so you pass Lib5E_CheckDamageModifiers
the name of the string variable you want to use and the damage type. The variable (ResistType
in this case) will include either nothing, * 2 [Vulnerable]
, \ 2 [Resistant]
, or * 0 [Immune]
which can be included in a roll assignment (--=
) to modify the damage as appropriate. The order here might be important if an NPC is misconfigured to be both resistant and immune to the same damage type. Since immune is an absolute, having it last ensures that it will override resistant or vulnerable. A creature that is both vulnerable and resistant (again, misconfigured) will come back as resistant since that condition is checked after vulnerable.
Some notes: I prefix my library labels with either Lib5E_
or _Lib5E_
as a clarity convention. This isn’t strictly necessary but you should be aware that if two libraries (or if your script and a library) define the same label, the last label defined will win. Since libraries are appended to the end of the script in the order you include them in the +++libname+++
directive, you can somewhat control this, but it is probably best to avoid re-declaring labels.
In my case, items beginning with Lib5E_
are intended to be called by scripts, while items beginning with _Lib5E_
are intended to be used as subroutines by the “public” procedures. Of course, there is no reason you couldn’t call them directly.
You might also note that I’ve included some library information in comment lines (--/|
) at the top of the library. These are ignored by ScriptCards, and are a good way to convey requirements, parameters, usage information, etc.
Example Libraries
dnd5elib
Download the dnd5elib Library from the ScriptCards GitHub
The dnd5elib library provides a collection of utility procedures that help simplify dealing with the D&D 5E Official Sheet. Some of the procedures in this library require ChatSetAttr to be installed in your game. This is a growing library, and currently only has a handful of routines. They are:
Procedure Name Notes Lib5E_CheckDamageModifiers parameters, pass the Lib5E_CheckDamageModifiers procedure a variable name (no reference information) and a damage type (i.e., fire, cold, bludgeoning, etc.), and the procedure will then create a string variable with with a name equal to the first parameter that you passed into the procedure. This variable will contain a string that can be included in a roll line (--=), in order to modify the roll as appropriate. For example, -->Lib5E_CheckDamageModifiers|ResistType;fire will check the current target character's attributes for "fire" and will either return an empty string (no references), "* 0 [Immune]" if the creature is immune, "\ 2 [Resistant]" if the creature is resistant, or "* 2 [Vulnerable]" if the creature is vulnerable to fire damage. Lib5E_DeductSpellSlot Pass in a character_id and a slot level, and the script will expend one spell slot of that level, capping the value at 0 slots remaining. For Example -->Lib5E_DeductSpellSlot|@{selected|character_id};1 to deduct a first level spell slot from the selected character. Lib5E_FindResource Used to locate a resource value on a character. Pass in a character_id, a resource name, and two variable names. The procedure will check both repeating and non-repeating resources looking for a resource whose name matches what was passed in and return three variables. The first will be a string variable named for the 3rd parameter and contains the attribute name of the resource's "name" field. The second will be a string variable named after parameter 4 and contains the resource's value field attribute name, and the third variable is a Roll Variable, also named after the 4th parameter that contains the current resource value. Example: -->Lib5E_FindResource|@{selected|character_id};Crossbow bolts;ResName;ResValue will find "Crossbow bolts" as a resource on the character and return [&ResName] which is the name of the resource attribute, [&ResValue] which is the name of the attribute that stores the value and [$ResValue] which is the current numeric value of the resource. Lib5E_Active_Global_Attack_Modifiers Pass a character ID and a string variable to set the return value. This procedure will look through the Global Attack Modifiers (repeating_tohitmod_*) for rows that are active (checked on the character sheet) and return a string with the dice rolls and descriptions for each (for example, if I have "Bless" for 1d4 active and "Being Cool" for +2 active, I will get a return string " + 1d4 [Bless] + 2 [Being Cool]" that can be used in a dice roll. Lib5E_Active_Save_Modifiers Pass a character ID and a string variable to set the return value. This procedure will look through the Global Save Modifiers (repeating_savemod_*) for rows that are active (checked on the character sheet) and return a string with the dice rolls and descriptions for each (for example, if I have "Bless" for 1d4 active and "Being Cool" for +2 active, I will get a return string " + 1d4 [Bless] + 2 [Being Cool]" that can be used in a dice roll. Lib5E_Active_Skill_Modifiers Pass a character ID and a string variable to set the return value. This procedure will look through the Global Skill Modifiers (repeating_skillmod_*) for rows that are active (checked on the character sheet) and return a string with the dice rolls and descriptions for each (for example, if I have "Guidance" for 1d4 active and "Being Cool" for +2 active, I will get a return string " + 1d4 [Guidance] + 2 [Being Cool]" that can be used in a dice roll. Lib5E_Active_AC_Modifiers Pass a character ID and a string variable to set the return value. This procedure will look through the Global AC Modifiers (repeating_acmod_*) for rows that are active (checked on the character sheet) and return a string with the dice rolls and descriptions for each (for example, if I have "Shield of Faith" with a value of 2 active, I will get a return string " + 2 [Shield of Faith]" that can be used in a dice roll. Lib5E_Active_Damage_Modifiers Pass a character ID and TWO string variable to set the return value. The first string will be for normal damage, and the second will be the additional damage on a crit. This procedure will look through the Global Damage Modifiers (repeating_damagemod_*) for rows that are active (checked on the character sheet) and return two strings with the dice rolls and descriptions for them (for example, if I have "Sneak Attack" with a value of 1d6 normal and 1d6 critical damage active, I will get a return string " + 1d6 [Sneak Attack]" and another string of " + 1d6 [Sneak Attack CRIT]" that can be used in a dice rolls. Lib5E_DivineSmiteDice Used to calculate the number of dice to be rolled for a paladin's Divine Smite. Pass a target token id, a spell slot level, and a string variable to be set to the dice roll amount based on the NPC_TYPE attribute of the target token. The returned variable will contain a dice roll (like "3d8" that can be used in a --= line) Lib5E_Character_Summary Pass a character ID to outputs a mini character sheet, including clickable buttons for attacks, actions, legendary actions, etc. Will automatically detect a PC vs NPC and output the appropriate sections.
Due to formatting issues with the Wiki, the library code has been moved to a GITHUB GIT. Please view the GIST in raw mode and copy the text and paste it into a handout called "ScriptCards Library dnd5elib" in your Roll20 Game.
Triggers
Triggers are a new feature introduced with ScriptCards 2.0.0 and allow you to establish a character in your game with abilities that will be executed in response to various game events that are exposed to the API. The idea here is that you can have things that happen in-game trigger ScriptCards scripts to be executed when the event occurs.
Examples for using ScriptCards Triggers can be found on the GitHub Repo.
What is an Event?
A Roll20 API script can register with the server to have functions executed when something changes in your campaign. There are three types
of events that ScriptCards can monitor: add, destroy, and change. (Note that there are two additional event types, “ready” and “chat” that
are not supported by ScriptCards Triggers.
Each of the event types is further classified by what time of object is impacted, so if an attribute on a character is changed, the
change:attribute
event will be executed. The following events can be used with ScriptCards Triggers:
change:campaign:playerpageid
Object Properties: &PreviousPageID and &NewPageID
change:campaign:turnorder
Object Properties: Currently there are no object parameters for the turnorder change event
change:character
Object Properties: &CharacterOld and &CharacterNew followed by the property name (ex. CharacterOldavatar) - _id, _type, avatar, name, archived, inplayerjournals, controlledby, _defaulttoken.
change:attribute:*
Object Properties: &AttributeOld and &AttributeNew followed by the property name (ex. AttributeOldname) - _id, _type, _characterid, name, current, max
add:graphic
Object Properties: &GraphicAdded followed by the property name (ex. GraphicAddedtop) - _id, _type, _subtype, _cardid, _pageid, imgsrc, represents, left, top, width, height, rotation, layer, isdrawing, flipv, fliph, name, gmnotes, tooltip, show_tooltip, controlledby, bar1_link, bar2_link, bar3_link, bar1_value, bar2_value, bar3_value, bar1_max, bar2_max, bar3_max, bar_location, compact_bar, aura11_radius, aura2_radius, aura1_color, aura2_color, aura1_square, aura2_square, tint_color, statusmarkers, showname, showplayers_name, showplayers_bar1, showplayers_bar2, showplayers_bar3, showplayers_aura1, showplayers_aura2, showplayers_aura3, playersedit_name, playersedit_bar1, playersedit_bar2, playersedit_bar3, playersedit_aura1, playersedit_aura2, lastmove, sides, currentSide, lockMovement
destroy:graphic
Object Properties: &GraphicRemoved followed by the property name (ex. GraphicRemovedtop) - _id, _type, _subtype, _cardid, _pageid, imgsrc, represents, left, top, width, height, rotation, layer, isdrawing, flipv, fliph, name, gmnotes, tooltip, show_tooltip, controlledby, bar1_link, bar2_link, bar3_link, bar1_value, bar2_value, bar3_value, bar1_max, bar2_max, bar3_max, bar_location, compact_bar, aura11_radius, aura2_radius, aura1_color, aura2_color, aura1_square, aura2_square, tint_color, statusmarkers, showname, showplayers_name, showplayers_bar1, showplayers_bar2, showplayers_bar3, showplayers_aura1, showplayers_aura2, showplayers_aura3, playersedit_name, playersedit_bar1, playersedit_bar2, playersedit_bar3, playersedit_aura1, playersedit_aura2, lastmove, sides, currentSide, lockMovement
change:graphic:
Object Properties: &GraphicOld and &GraphicNew followed by the property name (ex. GraphicOldtop) - _id, _type, _subtype, _cardid, _pageid, imgsrc, represents, left, top, width, height, rotation, layer, isdrawing, flipv, fliph, name, gmnotes, tooltip, show_tooltip, controlledby, bar1_link, bar2_link, bar3_link, bar1_value, bar2_value, bar3_value, bar1_max, bar2_max, bar3_max, bar_location, compact_bar, aura11_radius, aura2_radius, aura1_color, aura2_color, aura1_square, aura2_square, tint_color, statusmarkers, showname, showplayers_name, showplayers_bar1, showplayers_bar2, showplayers_bar3, showplayers_aura1, showplayers_aura2, showplayers_aura3, playersedit_name, playersedit_bar1, playersedit_bar2, playersedit_bar3, playersedit_aura1, playersedit_aura2, lastmove, sides, currentSide, lockMovement
add:page
Object Properties: &PageAdded followed by the property name (ex. PageAddedwidth) - _id, _type, _zorder, name, width, height, background_color, archived, jukeboxtrigger, showdarkness, fog_opacity, showgrid, grid_opacity, gridcolor, grid_type, gridlabels, snapping_increment, scale_number, scale_units, diagonaltype, dynamic_lighting_enabled, daylight_mode_enabled, daylightModeOpacity, explorer_mode, force_lighting_refresh, fog_opacity, lightupdatedrop, showlighting, lightenforcelos, lightrestrictmovement, lightglobalillum
destroy:page
Object Properties: &PageRemoved followed by the property name (ex. PageRemovedwidth) - _id, _type, _zorder, name, width, height, background_color, archived, jukeboxtrigger, showdarkness, fog_opacity, showgrid, grid_opacity, gridcolor, grid_type, gridlabels, snapping_increment, scale_number, scale_units, diagonaltype, dynamic_lighting_enabled, daylight_mode_enabled, daylightModeOpacity, explorer_mode, force_lighting_refresh, fog_opacity, lightupdatedrop, showlighting, lightenforcelos, lightrestrictmovement, lightglobalillum
change:page
Object Properties: &PageOld and &PageNew followed by the property name (ex. PageOldwidth) - _id, _type, _zorder, name, width, height, background_color, archived, jukeboxtrigger, showdarkness, fog_opacity, showgrid, grid_opacity, gridcolor, grid_type, gridlabels, snapping_increment, scale_number, scale_units, diagonaltype, dynamic_lighting_enabled, daylight_mode_enabled, daylightModeOpacity, explorer_mode, force_lighting_refresh, fog_opacity, lightupdatedrop, showlighting, lightenforcelos, lightrestrictmovement, lightglobalillum
Events marked with :* at the end require you to define the particular property of an object that you wish to be alerted to, as some changes can cascade into a huge number of event calls that can cause timing issues if you were to try to respond to them all. For example, you can watch for a particular attribute on a character sheet to change, such as “hp”, by using the event name “change:attribute:hp”, but you cannot watch ALL attributes (change:attribute is not supported).
Setting up for ScriptCard Triggers
In order to utilize ScriptCard Triggers, you will need to create a character in your game named exactly “ScriptCard_Triggers”. This name is case sensitive, and the character must exist in the game at the time the API sandbox starts for Triggers to be enabled. If you have a correctly named character, you will see a message in the API console similar to “ScriptCards Triggers Active. Trigger Character ID is -N1W93TIw0ofPHUglMV1” when the sandbox starts. If you add the character after the sandbox is running, just restart the sandbox from the API console to have the script re-detect the character.
Object Parameters are generated dynamically, so as Roll20 adds new object properties they will be automatically available to your triggers.
Setting up an Event Handler
In order to respond to events, you will need to create Abilities on the ScriptCards_Triggers character that are named after the event you wish to respond to. The content of the ability is the macro you wish to have execute when the event is triggered.
Note:There is no strict requirement that the executed even needs to be a ScriptCard – ScriptCards will simply sendChat whatever is in the ability – but if it is not a properly formed ScriptCard the object parameters that would be passed to a ScriptCard won’t be available.
Here is a sample ability, with the name “change:campaign:playerpageid”:
!script {{ --/|TRIGGER_REPLACEMENTS --#title|The action moves to... --#activepage|[&NewPageID] --+|[b][c][*P:name][/c][/b] }}
The most important component to notice here is the line --/
which will be replaced with the object parameters for
the object that triggered the event when it is called.
This simple script just displays a card letting the players know that the page has been changed and providing the name of the new page.
Object Parameters
All events include object parameters of some kind. For “change” events, there will be two sets of parameters: old values and new values. For “destroy” events, a full set of parameters for the item that was removed will be passed to the script. Finally, for “add” events, just the object ID of the new object will be provided.
For “change” events, a series of string variables will be created on the card that provide access to the object’s previous information with a name like “AttributeOldproperty” (such as AttributeOldcurrent for the value of the attribute before the change – as opposed to AttributeOldmax which would hold the maximum value). There is a similar set of variables for the new properties, named in the format AttributeNewproperty” (i.e., AttributeNewcurrent).
Note that ScriptCards variable names are case sensitive, and the property names are pulled from the objects themselves which can be referenced at API:Objects#Page. Note that there are some oddities in the way Roll20 names some properties by prefixing them with an underscore, so AttributeOld_characterid is correct, while AttributeOldcharacterid will return nothing.
API Generated Events
********Critical Note********: The Roll20 system only fires events in response to changes made through the UI. It does not fire events for
changes made to objects through the API, so setting an attribute value in ScriptCards or via Token Mod will not cause your triggers to fire.
A future update to ScriptCards will include firing of events for objects changed through the --!
command, but as of 1.9.5 this is not yet
implemented.
Override Templates
Introduced with version 2.2.0, Override Templates make use of a new feature of Keithcurtis' Supernotes 0.2.0 Mod that exposes a set of 10 (as of this writing) HTML templates that can be used to theme ScriptCards output.
To utilize one of these templates, include the #overridetemplate setting in your ScriptCards code (I recommend it be near the top of the code). Using an override template causes ScriptCards to ignore most of the visual output settings you may have included in your script in favor of the template.
Ex: --#overridetemplate|steam
The image below shows the same ScriptCards script run with different #overridetemplate values, which are case sensitive. All of Keith's templates are named with lowercase names. Included in the lower-left is the script run without an Override Template.
NOTE: This section is currently being written and will be expanded once the 2.2.0 version of ScriptCards has gone live on OneClick
What to Know if you are Coming from PowerCards
While ScriptCards and PowerCard have very similar output goals, their internals and use are quite different. The table below summarizes some of the major differences between the scripts. With its built in roll parser and true variable support, ScriptCards allows for much more powerful and flexible macro creation than what is possible in PowerCards simply because of its design.
PowerCards ScriptCards With a handful of exceptions, all lines in a PowerCard macro are intended to produce a line of output on the final card. With ScriptCards, ONLY the --+
and--*
statement types produces outputPowerCards lines begin with two dashes ( --
) followed by a unique tag name for the line, followed by a vertical bar and the content for the line.ScriptCards lines begin with two dashes ( --
) followed by a statement type identifier, which is a single character that identifies the type of line to the interpreter. This is followed by a tag (frequently optional), a vertical bar, and the parameters for the statement being executed.PowerCard macros are always processed top to bottom. Lines can be hidden so they don't output anything, but there is no looping or branching ( --SkipTo
looks like a branch, but it just hides all of the lines until the referenced label.)ScriptCards scripts support true branching, including direct branching ( --^
) and procedure branching (-->
) and (--<
). Procedures support parameters and a call stack so procedures can be nested to call other procedures. In addition, the --% statement type can be used to create for...next loops.All lines in a PowerCards macro need to have unique tags because PowerCards builds the card as a single JavaScript object using the tag names to store what will be displayed. This is why repeated tag names always result in the last one being shown. ScriptCards tags do not need to be unique, and in the case of many line types are optional. PowerCards conditionals result in either showing or hiding the line they are on. ScriptCards conditionals support branching, variable setting, loop control, and statement block initiation. Because conditional lines do not produce output on their own, the true/false value doesn't impact the display directly. PowerCards relies on the Roll20 Quantum Roll server and inline rolls for all dice functions ScriptCards includes its own dice roll parser, and does not parse inline rolls. If an inline roll is passed to ScriptCards, it will insert the final value of the roll in the place of the roll in the macro, but they are not part of or parsed by the built-in roll parser and cannot reference ScriptCards variables or updated while the script is running. PowerCards RollIDs (often mistaken for variables) are assigned by analyzing the results of an inline roll, and cannot be referenced in other rolls, so you can't roll a 1d4
and then roll a1d20
and add the1d4
result because all of the rolls happen on the chat server before PowerCards gets the macro text.ScriptCards supports two types of variables: Roll Variables
andString Variables
. Because ScriptCards uses its own roll parser and is not dependent upon the chat server, rolls and their results can be used in other rolls, math functions, output, etc.
Example Scripts
Note: The features available in ScriptCards have changed drastically since these examples were written. While these should still work, there are in many cases better ways to do things using language features introduces after these were constructed. Please see the Script Examples section of the official ScriptCards GitHub repository for more updated script examples.
Below are some sample scripts that utilize the various statement types in ScriptCards:
Divine Smite
This script will prompt the user for a spell slot level to expend on a divine smite. It will check the target's npc_type
to see if it is an Undead or Fiend, which adds an additional d8 to the smite roll.
!scriptcard {{ --#title|Divine Smite --=DiceCount|?{Spell Slot Level?|1|2|3|4|5|6|7|8|9} + 1 --=IsFiendOrUndead|0 --?"@{target|npc_type}" -inc fiend|>IsBoosted --?"@{target|npc_type}" -inc undead|>IsBoosted --=TotalDice|[$DiceCount] + [$IsFiendOrUndead] --=SmiteRoll|[$TotalDice]d8 --#emoteText|@{selected|token_name} smites @{target|token_name} --#sourceToken|@{selected|token_id} --#targetToken|@{target|token_id} --+Smite|deals [$SmiteRoll] radiant damage. --X| --:IsBoosted| --=IsFiendOrUndead|1 --<| }}
How It Works
The first line sets the "title" card parameter to "Divine Smite".
Line 2 Shows a query to the user asking for the spell slot level, adds one and stores the value in the "DiceCount" Roll Variable. The query/dropdown is generated by the chat server prior to the script being executed.
Line 3 defaults the "IsFiendOrUndead" Roll Variable to 0.
Lines 4 and 5 compare the target's "npc_type" attribute (passed by the chat server as text) to see if they include either "undead" or "fiend". If true, the IsBoosted subroutine will be called. No parameters are passed to this subroutine.
Line 6 sets the "TotalDice" variable to the base (DiceCount) number plus the IsFiendOrUndead number, which will be a 0 or a 1.
Line 7 calculates "SmiteRoll" by rolling a number of d8 equal to the "TotalDice" value.
Lines 8-10 set the parameters for the emote, which appears above the card content. By setting the sourceToken and the targetToken, their icons will appear in the emote surrounding the text describing the action.
Line 11 is the only line that actually produces output on the card. It results in "Smite deals # radiant damage".
Line 12 ends the script execution, preventing the script from continuing and running the subroutines out of context.
Lines 14-16 are the IsBoosted subroutine, starting with the :IsBoosted label. The IsFiendOrUndead variable is set to 1, and a return from subroutine is executed.
Alternative Script
!scriptcard {{ --#title|Divine Smite --#sourceToken|@{selected|token_id} --#targetToken|@{target|token_id} --=DiceCount|?{Spell Slot Level?|1|2|3|4|5|6|7|8|9} + 1 --?"@{target|npc_type}" -inc fiend -or "@{target|npc_type}" -inc undead|=DiceCount;[$DiceCount.Raw] + 1 --=SmiteRoll|[$DiceCount]d8 --#emoteText|@{selected|token_name} smites @{target|token_name} --+Smite|deals [$SmiteRoll] radiant damage. }}
This version of the Divine Smite script has identical output to the script above, but is greatly simplified by using language features introduced later in the ScriptCards development cycle. Instead of a subroutine that is called based on the undead or fiend values as separate checks, a single conditional is used joined by an -or
. The expanded capability of conditionals to set variables is then used to add one to the DiceCount if the conditional statement is true.
Magic Missile
This script demonstrates using a loop and calling a subroutine to fire a number of missiles determine by the spell slot level used to cast the spell.
!scriptcard {{ --#title|Magic Missile --#sourceToken|@{selected|token_id} --#targetToken|@{target|token_id} --=MissileCount|?{Spell Slot Level?|1|2|3|4|5|6|7|8|9} + 2 --=DisplayCount|1 --=MissileDamage|0 --#leftsub|Slot level ?{Spell Slot Level?} --#rightsub|Ranged Attack --#emoteText|Fred uses a level ?{Spell Slot Level?} spell slot to fire [$MissileCount.Total] missiles of magical force! --:MissileLoop| -->FireMissile| --=DisplayCount|[$DisplayCount] + 1 --?[$DisplayCount] -le [$MissileCount]|MissileLoop --+Total|Total damage is [$MissileDamage] --X| --:FireMissile| --=ThisMissile|1d4 + 1 --=MissileDamage|[$MissileDamage] + [$ThisMissile] --+Missile|[$DisplayCount.Total] Hits for [$ThisMissile] [b]force[/b] damage --<| }}
How It Works
Lines 1-3 set the card title, the source token and the target token. Setting these tokens causes their icons/avatars to appear in the Emote section of the card.
Line 4 asks the user what spell slot level they wish to use to cast magic missile. The number of missiles fired is equal to 2 plus the spell level, and this is stored in the MissileCount variable.
Line 5 stores a 1 in the DisplayCount variable. This will be used to control the loop to determine the number of missiles fired and the missile number when displaying damage rolls.
Line 6 initializes MissileDamage to 0
Line 7 sets the left subtitle to the text "Slot Level #", where # is the spell slot level being used.
Line 8 sets the right subtitle to the text "Ranged Attack".
Line 9 sets the emoteText parameter with a description of the action, including the slot level and number of missiles fired.
Line 10 is a label for the missile firing loop
Line 11 Calls the "FireMissile" subroutine
Line 12 increases the DisplayCount variable by 1
Line 13 Checks to see if there are still missles to fire (DisplayCount <= MissileCount) and if so branches to MissileLoop
Line 14 Displays the total damage dealt by the spell.
Line 15 stops execution of the script to prevent out of context execution of the subroutine.
Lines 76-21 are the FireMissile subroutine, beginning with the FireMissile label. The 1d4+1 is rolled and assigned to "ThisMissile". The result is added to the existing MissileDamage total, and a line for the current missile is displayed with the missile number and the damage for the missile.
Longsword Attack
This script demonstrates a standard 5E D&D melee weapon attack, including detection of misses, fumbles, hits, and critical hits. If installed, alterbars is used to decrement the target's BAR3 value by the damage dealt.
!scriptcard {{ --#title|Longsword --#leftsub|Melee Attack --#sourceToken|@{selected|token_id} --#targetToken|@{target|token_id} --#emoteText|@{selected|token_name} attacks @{target|token_name} --=TargetAC|@{target|npc_ac} --?[$TargetAC.Total] -gt 0|DoneWithAC --=TargetAC|@{target|ac} --:DoneWithAC| --=AttackRoll|1d20 + @{selected|strength_mod} [STR] + @{selected|pb} [PROF] --+Attack|@{selected|token_name} rolls [$AttackRoll] vs AC [$TargetAC]. --?[$AttackRoll.Base] -eq 20|Crit --?[$AttackRoll.Base] -eq 1|Fumble --?[$AttackRoll.Total] -ge [$TargetAC.Total]|Hit --+Miss|The attack missed. --^Final| --:Fumble| --+Fumble!|The attack went horribly wrong. --^Final| --:Hit| --=Damage|1d8 + @{selected|strength_mod} [STR] --+Hit!|The attack hit @{target|token_name} for [$Damage] slashing damage. --@alter|_target|@{target|token_id} _bar|3 _amount|-[$Damage] --^Final| --:Crit| --=Damage|1d8 + @{selected|strength_mod} [STR] + 1d8 [CRIT] --+Critical Hit!|The attack hit @{target|token_name} for [$Damage] slashing damage. --@alter|_target|@{target|token_id} _bar|3 _amount|-[$Damage] --:Final| }}
How it Works
In lines 1-5, we set the title, subtitle, and emote text along with the tokens for the emote area.
Lines 6-9 allow us to determine the AC of the target. On the 5E Roll20 sheet, NPCs armor class is stored in npc_ac
, while PCs armor class is in ac
. First we grab npc_ac
and if it is zero, we check ac
.
Line 10 rolls the attack roll, rolling 1d20 and adding the attacker's strength modifier and proficiency bonus
Line 11 displays the result of the attack roll on the card
Lines 12-14 determine what kind of result the attack had. If the .Base value of the roll was 20, we branch to "Crit". If it was 1, we branch to "Fumble". If the .Total
value of the roll was greater than or equal to the AC that was determined in Lines 6-9, we branch to Hit.
Assuming we didn't branc anywhere, the result of the attack was a miss, so we display that on line 15 and then branch to "Final"
This is followed by three branch segments, :Fumble
, :Hit
, and :Crit
. A fumble displays a text message and branches to :Final
.
On a hit or a crit, we roll Damage (adding additional damage dice on a crit). We display a "Hit!" or "Critical Hit!" message and then make an API call to AlterBars, passing it the token id, bar we want to modify (3 in this case), and the amount we want to modify by the Damage value.
Party Health Status
This example calculates the current Hit Points remaining and HP percentage for each character and creates a color-coded display with the current party status.
!scriptcard {{ --#title|Party Status --#titleCardBackground|#33CC33 --#oddrowbackground|#bfee90 --#evenrowbackground|#90eebf -->HealthCheck|@{Quej Grastra|character_id} -->HealthCheck|@{Brim Cheuto|character_id} -->HealthCheck|@{Odug Ututees|character_id} --X|End of card Execution --:HealthCheck| --=HealthPerc|[*[%1%]:hp] / [*[%1%]:hp^] * 100 \ 1 --=HealthColor|000000 --?[$HealthPerc.Total] -gt 50|HealthSkip --=HealthColor|FF0000 --:HealthSkip| --+[*[%1%]:character_name]|has [#[$HealthColor.RollText]][*[%1%]:hp] of [*[%1%]:hp^][/#] HP [R]([$HealthPerc.Total]%)[/R] --<|End of HealthCheck }}
How it Works
Lines 1-4, we set the card title, and set the title background and row background colors to shades of green.
Lines 5-7 make gosub calls the the "HealthCheck" subroutine, passing in the character ID of each of the named characters (these are the names of the characters in my test game)
Line 8 terminates the script execution.
The remaining lines of the script are the HealthCheck subroutine, which works like this:
Line 10 is the subroutine label (:HealthCheck
)
Line 11 uses the character id passed as a parameter and combines it with character attribute lookup *(...) to retrieve the value of hp
and hp^
for the character. The ^
character is used to specify that we want the MAX value for this attribute for the second call. We divide these two numbers and multiple by 100 to get a percentage. Finally, we use integer division by 1 to round the percentage and drop the decimals. The end result gets stored in the HealthPerc
roll variable.
Line 12 defaults to color of the health text to black
Line 13 check to see if the health percentage is greater than 50. If so, it branches to HealthSkip, preventing the script from executing line 13.
Line 14 sets the color of the health text to red
Line 15 is the label that will be branched to from Line 13 to skip the red coloring
Line 16 again uses character attribute substitution and the passed parameter value to output a display line containing the character name, the colorized health total, and the percentage value. The percentage is right-justified.
Line 17 returns from the HealthCheck subroutine.
Expanded Magic Missile Script
This is the expanded and enhanced version of the Magic Missile script covered in this video. It includes visual and audio effects, checking and deducting spell slots, and applying damage using either Token-Mod or Alterbars.
!scriptcard {{ --#title|Magic Missile --#sourceToken|@{selected|token_id} --#targetToken|@{target|token_id} -->GetAndCheckSlotInformation| --=MissileCount|[$SlotLevel] + 2 --=DisplayCount|1 --=MissileDamage|0 --#leftsub|Slot level [$SlotLevel] --#rightsub|Ranged Attack --#emoteText|@{selected|character_name} uses a level [$SlotLevel.Total] spell slot to fire [$MissileCount.Total] missiles of magical force! --:MissileLoop| -->FireMissile| --=DisplayCount|[$DisplayCount] + 1 --?[$DisplayCount] -le [$MissileCount]|MissileLoop --+Total|Total damage is [$MissileDamage] -->DeductSpellSlot| --#rightsub|Level [$SlotLevel] Left: [$SlotsRemaining] -->PlayEffects|none;burst-smoke;beam-magic;spell_01 -->ApplyDamageTokenmod|@{target|token_id};3;-[$MissileDamage] -->ApplyDamageAlterbars|@{target|token_id};3;-[$MissileDamage] --X| --:FireMissile| --=ThisMissile|1d4 + 1 --=MissileDamage|[$MissileDamage] + [$ThisMissile] --+Missile|[$DisplayCount.Total] Hits for [$ThisMissile] [b]force[/b] damage --<| --:GetAndCheckSlotInformation| --=SlotLevel|?{Spell Slot Level?|1|2|3|4|5|6|7|8|9} --=SlotsTotal|[*S:lvl[$SlotLevel]_slots_total] --=SlotsExpended|[*S:lvl[$SlotLevel]_slots_expended] --?[$SlotsExpended.Total] -ge [$SlotsTotal.Total]|NoSlotsLeft --<| --:NoSlotsLeft| --+|[*S:character_name] has no level [$SlotLevel.Total] spell slots available. --X| --:DeductSpellSlot| --=SlotsExpended|[$SlotsExpended] + 1 --@setattr|_charid [*S:character_id] _lvl[$SlotLevel]_slots_expended|[$SlotsExpended] _silent --=SlotsRemaining|[$SlotsTotal] - [$SlotsExpended] --<| --:PlayEffects|Parameters are : source effect; target effect; line effect; sound effect --vtoken|@{selected|token_id} [%1%] --vtoken|@{target|token_id} [%2%] --vbetweentokens|@{selected|token_id} @{target|token_id} [%3%] --@roll20AM|_audio,play,nomenu|[%4%] --<| --:ApplyDamageTokenmod|Parameters are tokenid;bar#;amount --@token-mod|_ignore-selected _ids [%1%] _set bar[%2%]_value|[%3%] --<| --:ApplyDamageAlterbars| --@alter|_target|[%1%] _bar|[%2%] _amount|[%3%] --<| }}
Hidden Roll
A roll where only the GM sees the result of the roll.
!script {{ --#title|Stealth Check --=Roll|1d20 + @{selected|stealth} --+|@{selected|token_name} attempts to move undetected... --*GMLine|@{selected|token_name} rolled a [$Roll] }}