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

Can you do math in roll template function?

1609931086
CKenny
Sheet Author
I was wondering if you can do something like this : {{#rollGreater() var1 (x + var2)}}     Stuff {{/rollGreater() var1 (x + var2)}} where x is a constant, var1 and var2 are from the roll macros. I haven't managed to make it work, any idea if that could work or if I did a mistake somewhere?
1609933016
GiGs
Pro
Sheet Author
API Scripter
No, unfortunately you cant do any calculations inside a rolltemplate. You have to do all calculations in the roll part before it is sent to the rolltemplate.
1609935887
CKenny
Sheet Author
Ah, thank you
1610000227
John D.
Pro
Sheet Author
CKenny, As GiGs says, you cannot perform mathematical operations in a roll template but you can perform all the mathematical operations you may want to evaluate in the roll behind individual roll template variables, then evaluate those results to reveal messages in the roll template. The D&D5e sheet is a good example of this concept and uses a single roll template for everything.  You should check it out for reference and inspiration. You can't store attributes from your character sheet without an accompanying dice roll, such as {{a= 1d20+@{var1}}}.  However!  If you already have a roll template variable containing your main dice roll then you can trick the character sheet into populating roll template variables by including this in the roll template variable: (1d1-1).  Examples: {{b= (1d1-1)+@{var1}}} {{c= (1d1-1)+(@{x}+@{var2})}}. You can also do dynamic evaluations using conditional statements  using the same (1d1-1) trick.  The beauty of this, too, is that if you're using 3D dice, 1d1 will not be rolled!  Be warned, though, using other legit dice like another 1d20 or 1d6, etc, will roll those additional 3D dice, so don't go crazy.  Unless that's actually what you want.  ;) One additional trick, if you want a roll button to have dynamic roll functions, you can store your various roll values in a select attribute and then call that attribute from the roll's value, such as value= @{dynamic_roll}, where the values of the select attribute could be <select name='attr_dynamic_roll'><option value='&{template:default} {{attack= [[1d20+@{str}]]}}'>Attack</option><option value='&{template:default} {{evade= [[1d20+@{dex}]]}}'>Evade</option></select> If you haven't already, you may also find utility in ScottC's reusable dice roll hack, just heed the warning that this might be a bug that could be patched later.  However, I found it to be really cool and helpful (hint, hint Roll20).  ;) This is an example of some of the tricks/techniques above I've been playing around with: <button class='sheet-button-red sheet-d6button' type='roll' name='roll_mainhand_skill' value='&{template:default} {{attacker= @{name}}} {{defender= @{target|token_name}}} [[ ([[@{acv}]]+[[@{ndice}d6k@{hldice}2cs12cf0]])-([[@{target|dcv}]]+[[@{target|ndice}d6k@{target|hldice}2cs12cf0]]) ]] {{miss= [[1d1cf1-1]]}} {{damage1= [[(1d1cf0-1)+@{static_attack_primary_damage1}]]}} {{damage2= [[(1d1cf0-1)+@{static_attack_primary_damage2}]]}} {{damage3= [[(1d1cf0-1)+@{static_attack_primary_damage3}]]}} {{damage4= [[(1d1cf0-1)+@{static_attack_primary_damage4}]]}} {{(1d1cf0-1)+damage5= [[@{static_attack_primary_damage5}]]}} {{damage6= [[(1d1cf0-1)+@{static_attack_primary_damage6}]]}} {{(1d1cf0-1)+damage7= [[@{static_attack_primary_damage7}]]}} {{damage8= [[(1d1cf0-1)+@{static_attack_primary_damage8}]]}} {{damage9= [[(1d1cf0-1)+@{static_attack_primary_damage9}]]}} {{damage10= [[(1d1cf0-1)+@{static_attack_primary_damage10}]]}} {{damage11= [[(1d1cf0-1)+@{static_attack_primary_damage11}]]}} {{damage12= [[(1d1cf0-1)+@{static_attack_primary_damage12}]]}} {{forcefield= [[(1d1cs0-1)+@{target|static_protection_forcefield_ar}-@{static_attack_primary_ispiercing}]]}} {{armor= [[(1d1cs0-1)+@{target|static_protection_parmor_ar}+@{target|static_protection_sarmor_ar}+@{target|static_protection_tarmor_ar}-((({{@{target|static_protection_parmor_ar},0}>1}*1)+({{@{target|static_protection_sarmor_ar},0}>1}*1)+({{@{target|static_protection_tarmor_ar},0}>1}*1))*@{static_attack_primary_ispenetrating})]]}} {{acv= $[[0]]}} {{attackroll= $[[1]]}} {{dcv= $[[2]]}} {{defenseroll= $[[3]]}} {{attack= $[[4]]}} {{attackmaneuver= @{static_attack_primary_maneuver}}} {{defensemaneuver= @{target|static_defense_primary_maneuver}}} {{attackerweapon= @{static_attack_primary_weapon}}} {{defenderweapon= @{target|static_defense_primary_weapon}}}'></button> Note: the damage might look wonky as I don't believe in rolling for damage.  Always seemed lame to me that a player could get excited by rolling to hit as best as they could, only to be bummed out by rolling the lowest damage possible.  So instead I calculate the range of possible damage for a weapon when it is armed and store those values in their own attributes/variables, and then call them on an attack roll.  I then use the #rolltotal helper function to display the actual damage done by how well a player succeeded in hitting their target.
1610031905
CKenny
Sheet Author
Thank you John D, you have given me much to think about