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

Using logical or in rolltemplate

1596475804
Marco M.
KS Backer
Sheet Author
API Scripter
Compendium Curator
Do you know if I can use use an array with rollTotal?  I have to roll 1d100 and i need 2 outputs from the same roll 1) the value in percentage (for example 68%) to compare against a target (68<10?) 2) the sum of units and tenths (6+8=14) for the raw damage. So far my best option war to get the result as a % and precompute the sum doing {{#rollTotal() roll 11}} 2 {{/rollTotal() roll 11}} {{#rollTotal() roll 12}} 3 {{/rollTotal() roll 12}} For all 100th possible rolls. This method works, however it's really easy to make a mistake. Since there are only 19 possible outcomes, I would prefer to use a logical or to do something like {{#rollTotal() roll 12 || 21}} 3 {{/rollTotal() roll 12 || 21}} Is there a way to do it? Or even better, is there a way to pass the SAME  result to the roll template as both {{res=[[1d100]]}} {{dmg=[[((@{res}}/10)>0)?(@{res}}/10):10)+((@{res}}%10)>0)?(@{res}}%10):10)]]}} The second option would be better, but i couldn't find a way to do it
1596478108
GiGs
Pro
Sheet Author
API Scripter
You cant do this (or anything like it): {{res=[[1d100]]}} {{dmg=[[((@{res}}/10)>0)?(@{res}}/10):10)+((@{res}}%10)>0)?(@{res}}%10):10)]]}} There's no way to use two different results from the same dice. Roll20 dice parsing doesnt allow for conditionals, and you want to use eacj dice in the 2d10 (d100) roll differently.  There is a recently discovered hack to reuse the same roll in different places, but that requires the rolls not be changed in anyway. You are trying to use the same two dice roll be used in different ways, and I cant think of a way to do that. You also cant do this: {{#rollTotal() roll 12 || 21}} 3 {{/rollTotal() roll 12 || 21}} rolltemplates are very simple. It looks like your only option is to do this {{#rollTotal() roll 11}} 2 {{/rollTotal() roll 11}} {{#rollTotal() roll 12}} 3 {{/rollTotal() roll 12}}
1596849761
Marco M.
KS Backer
Sheet Author
API Scripter
Compendium Curator
Darn, I suspected it... well I found a solution to at least minimize the possibility of mistake.  I compiled the html using PUG  that allows me to write small chunck of code that are converted into html. I use a mixin (function) to generate the result from each number and write it in  the correct place. Solution: Pug sourcecode: Mixin // - LETHALITY DAMAGE mixin lethaldamage(results,mult)     // parse the results and mult to be sure they integer - const val = parseInt(results) - const multfactor= parseInt(mult) // define tenth and units - const tenths = Math.floor(val/10) - const units = val%10 // if either unit or tenth is 0, assign 10, otherwise use the value // the damage is given by the sum of units and tenths, and it is doubled on a critical - const dmgs = (((tenths>0)?tenths:10)+((units>0)?units:10))*multfactor // the sign '|' tells pug that the text coming after it has to be written wysiwyg, the command '#{}' allows to reference the variable val | | {{#rollTotal() lethality #{val} }} // write the damage for each val .sheet-template-row span.inlinerollresult Damage: #{dmgs} | | {{/rollTotal() lethality #{val} }} | Main template.pug file // critical multiplier -const mult_crit = 2 // pug doesn't have 'for(i=1;i<=100;i++)' there are workarounds, but I decided to use the internal function each to make the loop each _, i in Array(100) // +<functionname>(arg1,arg2) call the function, I had to do i+1 cause it starts counting at 0 +lethaldamage(i+1,mult_crit) The output html after compiling the code is: {{#rollTotal() lethality 1}} <div class="sheet-template-row"> <span class="inlinerollresult">Damage: 22</span></div> {{/rollTotal() lethality 1}}            ... {{#rollTotal() lethality 67 }} <div class="sheet-template-row"> <span class="inlinerollresult">Damage: 26</span></div> {{/rollTotal() lethality 67 }}           ... {{#rollTotal() lethality 100}} <div class="sheet-template-row"> <span class="inlinerollresult">Damage: 40</span></div> {{/rollTotal() lethality 100}} It is a pretty easy work around and you don't need to check all lines of code if you have written the function correctly, the final result of the lethality roll can be seen here . Hope this might help other people with a similar problem