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

Macro nesting question: roll template -> button -> roll template

April 28 (2 years ago)

Edited April 28 (2 years ago)

Quick context

I'm a player in a D&D 3.5e campaign, and I'm working on a bespoke Google Sheet for my character. I've done stats. Now I'm working on combat actions (rolls). For every available action I want to generate a Roll20 macro inside the sheet that I can just copy/paste into chat.

Motivation (feel free to skip)

Some of those actions have a number of 'stages'. Like for a trip attack with the Improved Trip feat, the stages are as follows:

  • Roll an attack against AC;
  • On success, roll a contested strength check for tripping the opponent;
  • On success, roll another attack against AC;
  • On success, roll for damage.

The Problem

I'd like to reveal those combat stages gradually by pressing a button to move onto the next stage each time. I believe this should be possible if only I can figure out which HTML entities to replace, right? :-) That's where I'm stuck.

I've decided to start with a simple example, just to understand what's going on here.

The following roll template works fine. It creates a button which, when clicked, rolls a d20.

&{template:DnD35StdRoll} {{name=Eldric Stormwind}} {{notes=[Button](!
/r 1d20)}}

Now the following roll template doesn't work. It's supposed to show a button which pops up a second roll template with its own button, which rolls a d20.

&{template:DnD35StdRoll} {{name=Eldric Stormwind}} {{notes=[Button 1](!
&{template:DnD35StdRoll} {{name=Eldric Stormwind }} {{notes=[Button 2](!
/r 1d20 ) }} ) }}

It doesn't even render the first button properly. And I tried a number of variations. I can't figure it out.

In principle I'm not afraid of many recursive levels of HTML entity replacement, because Google Sheets allows me to write some Javascript code to automate that stuff. The problem is, I don't even understand in principle what I'm doing wrong.

Help!

Thanks in advance! :-)

April 28 (2 years ago)
timmaugh
Forum Champion
API Scripter

I'm not sure it's possible to do what you're looking to do the way you are looking to do it. Here are some workarounds to consider:

1. You can present all the buttons in a single template, with instructions for how/when to click them... I'll use a default template because I don't have a 3.5 game, nor am I familiar with that template... but something like this should be possible:


2. Another option is to present all the numbers/results in a single template and let the user just read them:

(Hmm... left a parentheses in there while editing; ignore that character!)

I don't know 3.5 rules so I faked a strength check in that line, but it's just to demonstrate the potential.

3. Finally, if scripts are available, metascripts (or ScriptCards) could handle all of the logic and conditionals, creating the die rolls as necessary and presenting only the information that would match the result (so not rolling the Trip strength check if the initial attack roll was unsuccessful, or not rolling the second attack roll if the trip failed, etc.)

If scripts are available, post back and I can cook up a metascript example.

April 28 (2 years ago)

Edited April 28 (2 years ago)

Thanks for the quick reply! I'll definitely consider option 1. But even with option 1, could those buttons at least generate another roll template in order to give me some more control over presentation / narration? Or would I be limited to simple `/r 1d20 + x` notation?

For what it's worth, I've played 5e with the Beyond20 browser extension. It is able to separate the attack and damage rolls with multiple styled boxes to show the rolls, and a button in the first one to roll the second. But I don't know how to access the macro code behind those.

As for scripts... I don't know, I've never heard of metascripts / ScriptCards. How do I know if those are available? Could I ask my DM to activate them?

April 28 (2 years ago)
timmaugh
Forum Champion
API Scripter

If the game owner is a pro member, scripts are available. S/He would just need to install them from the one-click.

(Go to the game page, click Settings > Mod (API) Scripts, then choose the script from the dropdown in the middle of the page and click "Install")

As for buttons producing templates... which themselves have buttons, etc.... I can do that with metascripts, but it requires an in-game character sheet, and it sounds like you're handling your sheet outside of the game and you just want to produce the command line you need to enter to make it happen.

That means that the best I can do with metascripts to help you would be to handle all of the logic and creating the extra verbiage as necessary so that you only have to click once, and the template output is as verbose as you need it to be to explain what the numbers mean.

Again, I don't have the full mechanics and I'm using the default template, but as a proof of concept, this command line:

!&{template:default} {{name=@{selected|token_name} - Trip Attack}} {{Base Attack=[[1d20>@{target|AC}]] }} {&if $[[0]] > 0}{{Trip Check=@{selected|token_name} [[1d@{selected|strength_mod}]] vs @{target|token_name} [[1d@{target|strength_mod}]] {&if $[[1]] >= $[[2]]}(***Success!***){&else}(***Unsuccessful!***){&end})}}{&if $[[1]] >= $[[2]]}{{Attack Roll=[[1d20>@{target|AC}]]}} {&if $[[3]] > 0}{{Damage=[[1d8]]}}{&end}{&end}{&end}{&simple}

Will conditionally produce more/less output depending on the progression of the rolls. Here are 3 outputs from it run in succession.

The first one failed on the initial attack (you could add the word "Miss" or "Unsuccessful" if it helped).

The second one connected and the trip check was successful, so we got to the second roll, which failed. Again, this could have text added to help explain.

The third shows a successful attack, followed by a successful check, followed by another successful attack, resulting in damage.


Thanks for your effort there! As it turns out, our DM has Plus, not Pro, so no luck.  

In the end, if what I want isn't possible with basic macros, I believe your option 1 (one card with multiple buttons) is probably the way to go here. Thanks for thinking with me!

April 30 (2 years ago)
GiGs
Pro
Sheet Author
API Scripter

Tim's method, of listing each button in order, is the best way, and the only real way to do this if you'r GM isnt a Pro subscriber. Roll20 doesnt handle conditional effects (if this, then that) and you have multiple conditionals (if this succeeds, then rol this; if that succeeds, then roll that, and so on).

The button method is pretty easy, and a better solution than trying to automate this. It facilitates conversation between player and GM, after all.

April 30 (2 years ago)

Edited April 30 (2 years ago)

To clarify, I wasn't intending to use conditional effects. Just a new button at each stage to press or not press. I didn't intend to use any automation. The problem seems to be nesting a roll template inside the effect of a button. I guess no amount of HTML entity-replacement will allow that?

April 30 (2 years ago)
GiGs
Pro
Sheet Author
API Scripter

I don't know if you can nest the code of a rolltemplate inside the button like you are doing above. You *can* create abilities or macros that contain the rolltemplate, and then have a button call them.

You might be trying to do too much in one place for roll20.

There are two things to note when nesting roll templates is that colons can break the roll buttons, and nested template syntax can break the outer template syntax.

To get around the colon issue is to have a forward slash somewhere before it; I tend to put it just after the ! at the start.

To avoid the nested template syntax problem you can use an HTML replacement for one of the opening braces.

So your initial broken macro (changed to use the default template) can be changed to

&{template:default} {{name=Eldric Stormwind}} {{notes=[Button 1](!/
&{template:default} {{name=Eldric Stormwind }} {{notes=[Button 2](!
/r 1d20 ) }} ) }}
April 30 (2 years ago)

Edited April 30 (2 years ago)

RainbowEncoder: Nice! :-D Looks like there's a way after all. Thanks for giving me somewhere to start!

Next thing to try is writing a script to generate arbitrary nesting depth. Let's see if it works! *fingers crossed*

Looks like I can just replace all opening and closing braces, which will actually make this easier.