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

RollButton depending on value

Sheet Author
Hey folks, I want to add a roll button that depending on the value of a field rolls two different templates with slightly different logic. Is this possible? And how to best do that?
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
This is definitely doable. There are two ways to do it that I see: My preferred method would probably be to utilize a very basic form of custom roll parsing to build the roll on the fly. Using a roll button with the template to be called stored in an attribute I'll demo option 1: <input type='checkbox' value='1' name='attr_use_other_template'> <button type='action' name='act_roll'>Roll Using one of two templates</button> <rolltemplate class="sheet-rolltemplate-primary"> primary rolltemplate: {{roll}} </rolltemplate> <rolltemplate class="sheet-rolltemplate-alternate"> alternate rolltemplate: {{roll}} </rolltemplate> <script type="text/worker"> const initiateRoll = function(event){ getAttrs(['use_other_template'],async (attributes)=>{ let useOther = +attributes.use_other_template;//ensure it's a number let template = useOther === 1 ? 'alternate' : 'primary';//If it's checked, use the alternate template let roll = await startRoll(`&{template:${template}} {{roll=[[1d20]]}}`); finishRoll(roll.rollId); }); }; on('clicked:roll',initiateRoll); </script> Gives the following output:
Sheet Author
Thanks Scott, that is easier then expected