Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Roll20 Tips and Tricks (Innovative Solutions to Common Problems)

February 21 (2 months ago)

Divided By Zero Line Kill

This is a tiny little trick that might have use for some of you - dividing by zero in an inline roll nulls the line the inline roll is on, but only that line in the message. This means you can selectively disable macros or parts of macros - for a simple example, let's say you have macro

&{template:default} {{name=Attack roll
}} {{Roll=[[1d20]]
}}
&{template:default} {{name=Bonus damage
}} {{Damage=[[1d6]]
}} [[1/@{selected|condition}]]

Here, the attack roll template comes out every time, but the bonus damage template comes out only if the condition attribute of the selected character is not 0.

February 25 (2 months ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter

I have been remiss in indexing this thread, and there have been some really amazing Tricks. The last five pages (two years!?!?) have been added to the top post index. If anyone discovers errors or omissions, please contact me in a PM.

Here's the rules for the thread, as a reminder:

The users on the forums have quite often devised solutions to common problems or activities by clever or innovative use of the interface. I thought it would be nice to have a thread to share the little tricks we have come up with. Note, this is not necessarily a place to post little-known intended uses of the interface (such as keyboard commands), but less conventional uses, or ways to use common tools with other resources (such as emojis in macro titles). These tricks may or may not require the use of subscriber level resources. If they don't—that's great, everyone can benefit. If they do—that's great too, because free users might see even more benefits to subscription.
Aside: This thread used to be called "Stupid Roll20 Tricks", so if you see a reference to a "Stupid Trick" that's where it comes from. It's not a judgment on anyone's trick. Roll20 asked for the name change several years ago.

NOTE: Please only post a complete trick here. If you want help working out what might become a trick, start it it in its own thread and please post here when complete. If you just wish to express thanks to someone who just solved a great mystery for you, that's fine—people need recognition for contributing Cool Stuff. Also, feel free to point out refinements or warnings about existing tricks. Every little bit helps. If your post is strong enough, I'll link it to the same line as the referenced post in the index. Just don't clutter the thread with too many thanks and especially long strings of quoted text and images. Help keep this thread clean, organized, and easy to read. — Thanks!
March 11 (1 month ago)

Edited March 11 (1 month ago)

Chat Menu Variables Trick


I've been working on a trick to pass variables (rolls) stored in Chat Menu Buttons.  I will update once it becomes more refined.  However, this is the first implementation.  This relies on integrating several other tricks like the re-use rolls trick ($[[0]]), various math tricks allowing re-use of rolls one time in a math roll or other roll, text and button formatting tricks, and copious amounts of HTML replacements to make sections evaluate at specific points in the order of operations.  In the sections below, I have underlined the text that needs to be replaced for your convenience.


Basic Single variable implementation


No Roll Template Button with printed variable

Here is the button that you place inside your main macro or ability that produces the variables to pass along. Note that there can be no line breaks.

[[5+5]] [BUTTON](`%{selected|ABILITY} {{[[[$[[0]]]]]}}style="border:1px solid white;background-color:rgb(206, 15, 105);padding:5px;color:white;display:inline-block;)


Here is the basic format required for the ability to use the stored variable.  Note that you will have to increment $[[0]] by 1 for every normal roll that doesn't call a variable within the ability.  A rule of thumb is, +1 for every use of "]]" not containing $[[#]].  Determining variable indexing gets a bit more complicated when you implement multiple variables.

&{template:default}  {{name=ABILITY}} {{1 if variable is greater than 5:= [[ ceil( ( $[[0]]-5 )/10000 ) ]]}}

IMPORTANT NOTES:

  1. Non-math only rolls involving 1d20 or other dice rolls print Rolling before the value in hidden text.  This will break the trick unless you nest non-math only rolls inside of something like a keep high roll such as [[ { [[1d20]] , [[0]] }kh1 ]].  This will make the desired roll index to store $[[2]] instead of $[[0]].
  2. Without using a roll template containing the button, all rolls must be on the "same line" as the button or the indexing will reset betwen the roll and printing the button.  The %newline% trick can be used for formatting if using the button without a roll template.
  3. The roll template in the ability is not strictly required unless you want to be able to hide the variables by removing the braces around the variable in the button.
  4. You can replace selected inside the button with a target or with a reference to a "macro mule" or replace the ability %{selected|ABILITY} all together with a macro #ABILITY if you don't want to use the selected token's ability.  Don't forget the space after ABILITY if you do this

Roll Template Button with printed variable

Here is the button that you place inside your main macro or ability that produces the variables to pass along. This time, using a roll template

&{template:default}  {{name=Chat Menu Variables Trick}} {{Variable A:=[[3+1]]}} {{Chat Menu:=[BUTTON](`%{selected|ABILITY} {{[[[$[[0]]]]]}}" style="border:1px solid white;background-color:rgb(206, 15, 105);padding:5px;color:white;display:inline-block;)}}


Here is the basic format required for the ability to use the stored variable.  Note that you will have to increment $[[0]] by 1 for every normal roll that doesn't call a variable within the ability.  A rule of thumb is, +1 for every use of "]]" not containing $[[#]].  Determining variable indexing gets a bit more complicated when you implement multiple variables.

&{template:default}  {{name=ABILITY}} {{1 if variable is greater than 5:= [[ ceil( ( $[[0]]-5 )/10000 ) ]]}}


Roll Template Button with invisible variable

Here is the button that you place inside your main macro or ability that produces the variables to pass along. This time, without braces around the variable in the button to make the passed through variables not print when the ability uses a roll template.

&{template:default}  {{name=Chat Menu Variables Trick}} {{Variable A:=[[3+1]]}} {{Chat Menu:=[BUTTON](`%{selected|ABILITY} [[[$[[0]]]]]" style="border:1px solid white;background-color:rgb(206, 15, 105);padding:5px;color:white;display:inline-block;)}}


Here is the basic format required for the ability to use the stored variable.  Note that you will have to increment $[[0]] by 1 for every normal roll that doesn't call a variable within the ability.  A rule of thumb is, +1 for every use of "]]" not containing $[[#]].  Determining variable indexing gets a bit more complicated when you implement multiple variables.

&{template:default}  {{name=ABILITY}} {{1 if variable is greater than 5:= [[ ceil( ( $[[0]]-5 )/10000 ) ]]}}

Single variable implementation inside Query


With template, printed variables

When placed inside a query, the HTML replacements become a little complicated for the first nesting.  This is because the query itself requires different replacements than the button.  After the first time, you just add amp; after every & as normal.  Here is the button nested inside a random query


&{template:default}  {{name=Chat Menu Variables Trick}} {{Variable 1:=[[1+2]]}} {{Variable 2:=[[3+4]]}} ?{Do you want to pass Variable 1 or Variable 2 through to the next ability button?|
 
Variable 1,{{Ability Menu: =[BUTTON](`%{selected|ABILITY} {{[[[$[[0]]]]]}}" style="border:1px solid white;background-color:rgb(206, 15, 105);padding:5px;color:white;display:inline-block;)}}|
 
Variable 2,{{Ability Menu: =[BUTTON](`%{selected|ABILITY} {{[[[$[[1]]]]]}}" style="border:1px solid white;background-color:rgb(206, 15, 105);padding:5px;color:white;display:inline-block;)}}}


Here is the basic format required for the ability to use the stored variable.  Note that you will have to increment $[[0]] by 1 for every normal roll that doesn't call a variable within the ability.  A rule of thumb is, +1 for every use of "]]" not containing $[[#]].  Determining variable indexing gets a bit more complicated when you implement multiple variables.

&{template:default}  {{name=ABILITY}} {{1 if variable is greater than 5:= [[ ceil( ( $[[0]]-5 )/10000 ) ]]}}


I may come back at a later date to update this trick making the documentation more detailed.  I am still testing the multi-variable version, which is easily possible.  However, variable indexing becomes a tad complicated.  I have a rudimentary version of it working that passes through 8 variables into some pretty complicated rolls in various sections of a roll template.  It just doesn't translate well into a generic ability useful for cut and paste then editing. 


Anyone who would like to try can just duplicate the text around the variables inside the button and play with the indexing of called variables in the ability.  A word of warning, this may require passing the same variable several times if a trick to fix the indexing isn't used like surrounding the roll with a keep high roll [[ { [[ $[[1]]+0 ]] , [[0]] }kh1 ]].  That will indroduce additional rolls that will execute before the stored variable rolls though.  Hence why I've bumped $[[0]] up to $[[1]] in the text.


Another nice thing I discovered is that there is no detriment to including extra variables that you don't use.  So you can pass variables to abilities on tokens that are written completely differently by writing the calls to the first set of variables outside of braces at the beginning of the second ability so those variables don't print out.  Then you can continue calling other variables used in the second set of abilities.  The order you pass variables through a button to a new ability matters but you can bypass those limitations by passing everything twice in two different orders.  The ability using the first set of variables will be completely unaffected.


You can pass the same variable to the button over and over again with no issue as well.  Just keep duplicating the text around the variables with the same index.  The only time duplicating an index is an issue is when you try to do math with it.  Any math must be done in the first call to the variable.

March 11 (1 month ago)

Ah, that is quite familiar stuff, nice to see someone else work on the same stuff. You can simplify the indexing by placing the stored numbers ahead of the ability call, rather than after it.

March 11 (1 month ago)

Edited March 11 (1 month ago)

Very true, but you can't do math with the number if you do that.  I started that way too.  XD


Got any links to where you've posted it before.  I'm interested in any extra stuff that can be done with this!

March 11 (1 month ago)

Actually, the simplest solution is to just put the template row directly in the button and call the value there in the initial macro - such as {{if variable is greater than 5=[[{$[[1]],0}>6]] }} - that way you get around all that indexing nonsense that you really don't need to mess with in a non-recursive macro. I used $[[1]] in this example because if $[[0]] was a roll, you could still use it, but you'd need to place it in another set of inline rolls to get a plain numeric result.

March 11 (1 month ago)

Edited March 11 (1 month ago)

For some reason, I couldn't get that working as written.  Still trying to troubleshoot why, but yes you definitely can write the entire ability directly into the button since that is all roll20 is doing when it replaces the called ability or macro.  However, if you don't write the stored variables after the new rolls you are doing on button click, then you can't do this.  Can you? (I stopped collecting the pictures to include when I realized)


...

Actually, now that I think about it... you can just store the attributes you want to pass as numbers instead of as rolls if you write the entire ability into the button.  You would be SOL for any dice rolls you want to duplicate in a math roll after button press because it prints the word "rolling" as a hidden word attached to the value.  The above method bypasses that.  Other than that, you can greatly simplify things with your suggestion.

April 06 (3 weeks ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter

Disabling the API in a Pro Game With Many Scripts

Sometimes you need to troubleshoot a problem in a game that has scripts. You believe that some script might be the issue, but it's a pain to disable them one-by-on manually—or by halves if you are trying to isolate the issues to a particular script. If you want to turn ALL scripts off at once, install the following scriptlet:

StopAPIServer

StopAPIServer();

Since no such function exists, this will throw an error message and deliberately crash the sandbox. To return the sandbox to normal function, remove or disable this scriplet. I would suggest simply disabling it, since it provides you with an easy "on-off" switch.

Thanks to the Acrane Scriptmancer The Aaron for this idea.

April 06 (3 weeks ago)
GiGs
Pro
Sheet Author
API Scripter

Thats very handy and clever.

Toggleable template fields, a simpler query approach

Previous iterations of query controlled toggleable template fields used roll comments to hide template fields, which created some caveats in how to reuse rolls. By altering the query to include the start of a template field rather than a roll the query can be used to selectively complete template fields. As such previous caveats on roll reuse no longer apply.

The query would look as the following:

?{Section|Show,{|Hide,}

An example macro being

&{template:default} {{Always Show=[[d20]]}} ?{Section|Show,{|Hide,}{Sometimes Show=[[1d8]]}} ?{Section}{More Optional Fields}}

Note how the optional fields only have a single {, this prevents them from being shown unless the query adds an additional { to complete the template field

Use separate queries you can also have multiple selections

[[1d20 Always Shown]] [[1d8 Section 1]] [[1d6 Section 2]] &{template:default} {{Always Show=$[[0]]}} ?{Section 1|Show,{|Hide,}{Using Section 1}} ?{Section 1}{Section 1=$[[1]]}} ?{Section 2|Show,{|Hide,}{Using Section 2}} ?{Section 2}{Section 2=$[[2]]}}

One caveat with this approach is that new lines inside these templates will break the command apart. As such any new lines should be replaced by %NEWLINE%