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 .
×

Custom Role Parsing: how to add a class to the roll template depending on result of computation?

I would like to add a custom class to a div with a class  sheet-template-row in the roll template that displays the results, depending on what the computation yields (success, failure). This is the action call: <button type="action" class="dice d100" name="act_pw_st"></button> This is my rolltemplate: <rolltemplate class="sheet-rolltemplate-pw">   <div class="sheet-template-container">    <div class="sheet-template-header">{{name}} für {{character}}</div>    <div class="sheet-template-content">     <div class="sheet-template-row">      {{computed::roll1}}     </div>    </div>   </div> </rolltemplate> This is the worker sheet code: <script type="text/worker">   let lookupPw = {     'st': {       'name': 'Stärke',       'attribute': 'St',       'bonus': 'ItemBStärke'     }   }   // Custom Role Parse für Prüfwürfe   //let pwlist = ["st", "gs", "gw", "ko", "in", "zt", "au", "pa", "wk", "git", "kaw"];   let pwlist = ["st"];   pwlist.forEach(pw => {     on(`clicked:pw_${pw}`, event => {       const roll_string = `&{template:pw} {{name=Prüfwurf auf ` +  lookupPw[pw]['name'] + `}} für {{character=@{character_name}}}  {{roll1=[[1d100cs1cf100]]}} {{basiswert=[[@{`+ lookupPw[pw]['attribute'] + `}]]}} {{bonus=[[@{`+ lookupPw[pw]['bonus'] + `}]]}} {{modifier=[[@{popBonusAttribute}]]}}`;       startRoll(roll_string, (roll) => {         console.log(roll);         let basis = roll.results.basiswert.result;         let bonus = roll.results.bonus.result         let rollresult = roll.results.roll1.result;         let modifier = parseInt(roll.results.modifier.result);         let addendum = '';         let resultdetail =  (modifier != 0) ?             ' (' + rollresult + '+' + modifier + ')' :             '' ;         let basisdetail =  (bonus != 0) ?             ' (' + basis + '+' + bonus + ')' :             '' ;         if (modifier < 0) {           addendum = ' Der Wurf war erleichtert um ' + Math.abs(modifier) + '.';         }         if (modifier > 0) {           addendum = ' Der Wurf war erschwert um ' + modifier + '.';         }         let comp1 = basis + bonus;         let comp2 =  rollresult + modifier;         let compare = comp1 - comp2;         let computed = '';         let success = '';         if (compare < 0){           computed = 'Misserfolg: Der Wurf von ' + comp2 + resultdetail + ' ist um ' + Math.abs(compare) + ' schlechter als der Wert für ' + lookupPw[pw]['name'] + ' von ' + comp1 + basisdetail + '.'           success = 'failure';         } else {           computed = 'Erfolg: Der Wurf von ' + comp2 + resultdetail + ' ist um ' + compare + ' besser als der Wert für ' + lookupPw[pw]['name'] + ' von ' + comp1 + basisdetail + '.';           success = 'success';         }         if (addendum.length > 0) {           computed += addendum;         }         $20('.sheet-rolltemplate-pw .sheet-template-row').addClass(success);         finishRoll(             roll.rollId,             {               roll1: computed             }         );       });     });   }); </script> So first of all, in order to specifically target the message div that corresponds to the roll output, I need to find its message-id, right? Is there a way to derive that? Second of all, even the unspecific $20('.sheet-rolltemplate-pw .sheet-template-row').addClass(success); doesn't seem to add any class to the div.  Is there an easy way to style the roll output from within the custom role parser code in the worker sheet?
1770791866
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
unfortunately, you can't add a class by changing roll contents post roll. So instead you need to use roll template conditionals for displaying the element with and without the class based on the result of a roll.
1770806342

Edited 1770806384
Thanks, that pointed me in the right direction to solve my problem by adjusting my rolltemplate like this: <rolltemplate class="sheet-rolltemplate-pw">   <div class="sheet-template-container">     <div class="sheet-template-header">{{name}} für {{character}}</div>     <div class="sheet-template-content">       {{#rollGreater() computed::show 0}}       <div class="sheet-template-row success">         <span class="success">Erfolg:</span> {{computed::roll1}}       </div>       {{/rollGreater() computed::show 0}}       {{#rollLess() computed::show 1}}       <div class="sheet-template-row failure">         <span class="failure">Misserfolg:</span> {{computed::roll1}}       </div>       {{/rollLess() computed::show 1}}     </div>   </div> </rolltemplate> and then computing the value for show in the custom role parser function.
1770825708
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Yep! That is exactly how I would have done it.