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

Rolltemplate question

1664484271

Edited 1664484386
Fred
Pro
I want to write a very straightforward roll template but I don’t know how This template is very simple : 1d100 roll under a given target score (character attribute ± modifiers). I want to display special results this way : a roll of 01 to 09 is always a critical success, and a score of 91 to 99 a critical failure. So far so good, I know how to do this using the classic rolltemplate in the character sheet. Now here's my problem. I want to restrict the special results this way : critical success will apply only if the target score is 20 or more (in other words above 19) and critical failure will apply only if the target score is 80 or less (in other words below 81). I wonder if this is achievable using the standard character sheet rolltemplate.
1664485911
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
It might be possible with a very complex roll template, but your better bet is to just use custom roll parsing in your sheet.
1664488588
GiGs
Pro
Sheet Author
API Scripter
Are you saying a critical success applies if the roll is 01-09, and that target is above 19? This is doable with a classic rolltemplate, you just need to nest the cobditions inside each other (I don't know if rolltemplates support AND logic which would be even better). If you post your roll template code and a typical roll macro, we can show you how to modify it.
1664490100

Edited 1664490123
Fred
Pro
Yes GiGs, a critical success applies if the roll is 01-09, and that target is above 19 and a critical failure applies if the roll is 91-99, and that target is below 81. Here's the character sheet (where the character attribute is COM)  : <div class="thead"><button type="roll" class="bcar" name="COM" value="&{template:wiz} {{pc=@{character_name}}} {{name=Combat (COM)}} {{roll=[[1d100]]}} {{target=[[@{COM}+(?{Bonus(+)/Malus(-)|0})[Bonus/Malus]]]}}">COM</button></div> Now the rolltemplate : </rolltemplate> <rolltemplate class="sheet-rolltemplate-wiz">   <div class="tplmain">      <div class="pc">{{name}}</div>      <div style="display: table;">         {{#target}}         <div style="display: table-row;">            <div class="jet"><span style="font-family: dicefontd10;font-size: x-large;">t</span> {{roll}} ≤ {{target}} <span style="font-size: larger;">✶</span></div>            <div class="jet">             {{#rollGreater() roll target}}                 <span class="failure">Failure</span>                 {{/rollGreater() roll target}}                 {{#rollTotal() roll target}}                 <span class="success">Success</span>                 {{/rollTotal() roll target}}                 {{#rollLess() roll target}}                 <span class="success">Success</span>                 {{/rollLess() roll target}}           <div class="jet" style="display: table-row;">   {{#rollTotal() roll 01}}         <span class="special">Critical !</span>        {{/rollTotal() roll 01}}  {{#rollTotal() roll 02}}         <span class="special">Critical !</span>        {{/rollTotal() roll 02}}  {{#rollTotal() roll 03}}         <span class="special">Critical !</span>        {{/rollTotal() roll 03}}  {{#rollTotal() roll 04}}         <span class="special">Critical !</span>        {{/rollTotal() roll 04}}  {{#rollTotal() roll 05}}         <span class="special">Critical !</span>        {{/rollTotal() roll 05}} {{#rollTotal() roll 06}}         <span class="special">Critical !</span>        {{/rollTotal() roll 06}} {{#rollTotal() roll 07}}         <span class="special">Critical !</span>        {{/rollTotal() roll 07}} {{#rollTotal() roll 08}}         <span class="special">Critical !</span>        {{/rollTotal() roll 08}} {{#rollTotal() roll 09}}         <span class="special">Critical !</span>         {{/rollTotal() roll 09}}  {{#rollTotal() roll 91}}         <span class="special">Critical !</span>        {{/rollTotal() roll 91}} ....and so on up to 99 Scott C. helped me in the past with rolltemplate syntax, but I don't understand at all how custom roll parsing works.
1664496131
GiGs
Pro
Sheet Author
API Scripter
You have a lot of rollTotals there, you can replace them with rollLess(), and the high end, rollGreater(). It's that you use rllLess and rollGreater in other places but not there. When you ask for 20, are you referring to the full target with the modifier (@{COM}+?{Bonus(+)/Malus(-)|0)|0}) or just @{COM}? You also have this:                  {{#rollTotal () roll target }}                      < span class= "success" > Success </ span >                 {{/rollTotal () roll target }}                 {{#rollLess () roll target }}                      < span class= "success" > Success </ span >                 {{/rollLess () roll target }} I'd recommend swithing this to NOT RollGreater(), which means you only need a single comparison. The NOT operator is ^ sp that would be written like                  {{^#rollGreater () roll target }}                      < span class= "success" > Success </ span >                 {{^/rollGreater () roll target }} I'd also combine the critical test with the success test. I don't know what your extreme failure is called, I've named it fumble here. So I'd rewrite the test of your original rollTemplate like this:             {{ #^rollGreater() roll target }}                 {{#rollLess () roll 10 }}                     < span class= "special" > Critical ! </ span >                 {{/rollLess () roll 10 }}                 {{#rollGreater () roll 9 }}                     < span class= "success" > Success </ span >                 {{/rollGreater () roll 9 }}             {{ / ^rollGreater() roll target }}              {{#rollGreater () roll target }}                 {{#rollGreater () roll 90 }}                     < span class= "fumble" > Fumble ! </ span >                 {{#rollGreater () roll 90 }}                 {{#rollLess () roll 91 }}                     < span class= "failure" > Failure </ span >                 {{/rollLess () roll 91 }}             {{/rollGreater () roll target }} This doesn't yet answer your question, but makes your original code a lot simpler. Now to answer your specific question. You just nest your test inside the above construction.In the code eblow I test if a roll is NOT greater than the target (is less than or equal), and if so, I test if if it is below 10 (9-). If that is true, there are two possibilities: it is eitehr a critical or success, so I use logical helpers again to check that.             {{ #^rollGreater() roll target }}                 {{#rollLess () roll 10 }}                     {{#rollLess () target 20 }}                         < span class= "success" > Success </ span >                     {{/rollLess () target 20 }}                     {{#rollGreater () target 19 }}                         < span class= "special" > Critical ! </ span >                     {{/rollGreater () target 19 }}                 {{/rollLess () roll 10 }}                 {{#rollGreater () roll 9 }}                     < span class= "success" > Success </ span >                 {{/rollGreater () roll 9 }}             {{ / ^rollGreater() roll target }}              {{#rollGreater () roll target }}                 {{#rollGreater () roll 90 }}                     {{#rollGreater () target 80 }}                         < span class= "failure" > Failure </ span >                     {{/rollGreater () target 80 }}                     {{#rollLess () target 81 }}                         < span class= "fumble" > Fumble ! </ span >                     {{/rollLess () target 81 }}                 {{#rollGreater () roll 90 }}                 {{#rollLess () roll 91 }}                     < span class= "failure" > Failure </ span >                 {{/rollLess () roll 91 }}             {{/rollGreater () roll target }} Scott's suggestion of using CRP will make the rollTemplate a lot clearer, but you'll need a sheet worker that might be harder to write.
1664541003

Edited 1664541052
Fred
Pro
Thank you very much GiGs I confirm I am referring to the full target with the modifier. In other words a 01-09 will be a critical if the full target with the modifier was 20 or more, otherwise it is a standard success if the full target with the modifier was 19 or less (and of course it is a failure if the roll is above the full target with the modifier, ie roll of 07 vs full target of 06). A 91-99 roll will be a fumble if the full target with the modifier was 80 or less, otherwise it is a standard failure if the full target with the modifier was 81 or more. Anyways, I tried your code but I can't get it working, I think it might be because I have to modifiy the code of the roll button in order to define what target 19, target 20, target 80 and target 81 means ?
1664565379
GiGs
Pro
Sheet Author
API Scripter
you shouldnt need to modify the roll button, but it's certainly possibly my code has a syntax error in it. Can you describe what error if any you are seeing? Also did you try the first version?
1664657067

Edited 1664658401
Fred
Pro
Hello GiGs and thank you again. I got it working after making a correction :             {{ #^rollGreater() roll target }}                 {{#rollLess () roll 10 }}                     < span class= "special" > Critical ! </ span >                 {{/rollLess () roll 10 }}                 {{#rollGreater () roll 9 }}                     < span class= "success" > Success </ span >                 {{/rollGreater () roll 9 }}             {{ / ^rollGreater() roll target }}              {{#rollGreater () roll target }}                 {{#rollGreater () roll 90 }}                     < span class= "fumble" > Fumble ! </ span >                 {{ / rollGreater () roll 90 }}      [I turned the # into a /]                 {{#rollLess () roll 91 }}                     < span class= "failure" > Failure </ span >                 {{/rollLess () roll 91 }}             {{/rollGreater () roll target }} It works like a charm, I thank you very much for your precious help. I didn't knew about these target X codes (target 80 for example).
1664658055

Edited 1664658114
GiGs
Pro
Sheet Author
API Scripter
Without the complete code to test, I can't really say what the issue is (it's very easy for there to be another syntax error!), I can just encourage you to try to add the method I suggested. In this section:              {{#rollLess () roll 10 }}                     < span class= "special" > Critical ! </ span >              {{/rollLess () roll 10 }} add a nested check for target under 20, like              {{#rollLess () roll 10 }}                    {{#rollLess () target 20 }}                         < span class= "special" > Critical ! </ span >                                        {{/rollLess () target 20 }}                     {{#rollGreater () target 19 }}                         < span class= "success" > Success </ span >                     {{/rollGreater () target 19 }}              {{/rollLess () roll 10 }} This is combining the testing of a roll below 10, and the target is below 20. I can see no reason this would fail. (Does anyone know if there is a way to use AND logic here?) See if that works. Just make one change at a time, test that, then make the next change.
GiGs I got the 2nd version working perfectly and edited my post above, it works wonders, thank you very much :) Last question : are the "target X" commands documented somewhere ?
1664659873

Edited 1664662109
GiGs
Pro
Sheet Author
API Scripter
Yay! The technique there is just using the logic helpers (rollLess, rollGreater, as described). You know all the properties you create in a roll? {{roll=, {{target= ? You are creating a variable with those that rolltemplates can see and address with those logic helpers. The rolltemplate language is a bit clunky, and you have to sometimes use lots of nesting to achieve the outcome you want. It's based on a computer language called Handlebars, and I should check that out to see if there's a more elegant way to do this.
I can more or less handle the logic helpers but I was not aware you could nest into them a condition depending on the target score being below or above a given number, that's really new to me !