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

Conditional Roll Template Help

I'm really struggling to implement the  Helper Functions  in the Wiki into my roll template. Hoping someone can advise (or show me something better). As it stands, my template displays the PC's name, the test they are making, the number of successes (6s on d6s) and the number of failures. All good. Button code: <button class="blank-roll-button" type="roll" value="&{template:fear} {{name=@{roller}}} [[ @{log}+?{Bonus dice|0} - [[ [[{@{log}+?{Bonus dice|0},1}kh1]]d6>6]] ]] {{result=$[[1]]}} {{fails=$[[2]]}} {{roll_name=FEAR (?{Fear Level|0})}}" name="roll_fearCheck">...</button> Roll-template code: <rolltemplate class="sheet-rolltemplate-fear">     <table>         <tr><th>{{name}}</th></tr>         <tr><th>{{#roll_name}} {{roll_name}}{{/roll_name}}</th></tr>         <td class="result">{{result}} Successes {{fails}} Failures</td>     </table> </rolltemplate> What I want to add is some text and the solution to the sum  ?{Fear Level} - {{result}}   on the condition that  ?{Fear Level} > {{result}} , but nothing if not. Any attempt I make to implement a Helper Function, like {{#rollLess() <rollname>}} just breaks the template completely.
1601564958

Edited 1601565005
GiGs
Pro
Sheet Author
API Scripter
When you have properties like these: $[[0]]  it's important to realise they aren't numbers . They are objects of some sort that show  a number. This means you cant perform arithmetic with them, so this will not work:   ?{Fear Level} - {{result}} In addition, you cant perform arithmetic inside a rolltemplate. All arithmetic has to be done in the button roll before sending to the rolltemplate. So if you want to show that sum you need to modify the inline roll to include it. That's tricky in your case because you are already doing something with the result.  This might work: <button class="blank-roll-button" type="roll" value="&{template:fear} {{name=@{roller}}} [[ ?{Fear Level|0} + @{log}+?{Bonus dice|0} - [[ @{log}+?{Bonus dice} - [[ [[{@{log}+?{Bonus dice|0},1}kh1]]d6>6]] ]] ]] {{result=$[[1]]}} {{fails=$[[2]]}} {{fear=$[[3]] }} {{roll_name=FEAR (?{Fear Level})}}" name="roll_fearCheck">...</button> Note:  the line breaks here are for the forum. In your character sheet there should be no linebreaks in this code. This adds another level of nesting, and to achieve the Fear - result calculation you need, it adds the log and bonus dice back in. Then to update your template (which includes a syntax error, the result line needs to be inside a <tr></tr> block: <rolltemplate class="sheet-rolltemplate-fear">     <table>         <tr><th>{{name}}</th></tr>         <tr><th>{{#roll_name}} {{roll_name}}{{/roll_name}}</th></tr>         <tr>             <td class="result">{{result}} Successes {{fails}} Failures</td>         </tr>         {{#rollGreater() fear 0}}             <tr><td>some text and Fear sum: {{fear}}</td></tr>         {{/rolGreater() fear 0}}     </table> </rolltemplate>
Thanks for the tip, but still no good. I thought this would be a big ask when, as you note, I already have the multiple-results trick in play. Even the {{fear=$[[3]]}} is resolving to the same as {{fails=$[[2]]}}. Thanks anyway. I'll look into an alternative solution. Also, none of my roll templates have the result line in a <tr></tr> block but work fine regardless. What is it supposed to be for?
1601572098
Andreas J.
Forum Champion
Sheet Author
Translator
Btw I notice you're using html tables in your roll templates, and it might be a good idea to use Jacob's Better default Roll Template as your base instead. When using other things than html tables in the design, things become more flexible to design and make changes to.
1601572566
GiGs
Pro
Sheet Author
API Scripter
Rich K. said: Also, none of my roll templates have the result line in a <tr></tr> block but work fine regardless. What is it supposed to be for? In a table, <table> starts a table, </table> ends it. <tr> starts a new row, <td> starts a new column within that row. The / version ends the column and row. <th> starts a heading column, which is formatted differently from a td by default, but they otherwise work the same.
Thanks GiGs, that's good to know. Thanks Andreas J, I'll definitely check that out.
1601574192
GiGs
Pro
Sheet Author
API Scripter
I should add, regarding the table syntax: html is a very permissive language and will accept a lot of errors. Things with wrong syntax will often work - until they don't. One error will take things too far, and then it will fail so bad you'll have a devil of a time trying to figure out which error is the one causing the issue. So its best to get the syntax right, even if it appears  to not be needed. It'll teach you good habits, make code that's easier for others to edit, and save you BIG headaches later.
Wise words, thanks!