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

No idea why this scriptworker rolltemplate code doesn't work ;-;

1709271364
Cc
Pro
Sheet Author
I've gotten scriptworkers to work just fine with rolltemplates in my past code, but this most recent rolltemplate fails to load text or numbers into chat when the "Calculate Damage" button is click, just a blank message instead.  I've wittled down the issue to either the startRoll command or the rolltemplate itself. All other code works as intended. For testing purposes, assume "dmgcrt" is 3. <div class="dmgboxhit"> <input type="number" name="attr_dmgboxhit" min="0" style="width: 34px;"></div> <rolltemplate class="sheet-rolltemplate-damage"> <div class="sheet-template-container"> <h2>Damage Risk</h2> <div class="sheet-results"> <h2>{{rolldamage}}</h2> </div> </div> </rolltemplate> <script type="text/worker"> on("clicked:calcdmg", function() { getAttrs(["dmgboxhit","dmgcrt"], function(values) { let dmgboxhit = parseInt(values.dmgboxhit)||0; let dmgcrt = parseInt(values.dmgcrt)||0; let rollover = dmgboxhit - 1; if(values.dmgcrt >= rollover) { setAttrs({ "damagerisk": rollover + dmgcrt }); } if(values.dmgcrt < rollover) { setAttrs({ "damagerisk": dmgcrt * 2 }); } if(dmgboxhit == 0) { setAttrs({ "damagerisk": 0 }); } }); }); </script> <script type="text/worker"> on('clicked:calcdmg', (info) => { getAttrs(["damagerisk"], function(values) { startRoll("&{template:simple} {{name=Risk}} {{rolldamage=[[[[floor(@{damagerisk})]]d6s>5]]}}", (results) => { }); }); }); </script>
1709271744
vÍnce
Pro
Sheet Author
Hi Cc, just a quick observation; Your startRoll shows '&{template:simple', but the html shows ' <rolltemplate class="sheet-rolltemplate-damage">'
1709272327
Cc
Pro
Sheet Author
Works! Thank you so much!
1709277887
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
additionally, not sure if you just removed it to save space in the post, but you don't actually finish the roll. I'd also recommend putting all your sheetworkers in a single script tag.
1709345264

Edited 1709345319
GiGs
Pro
Sheet Author
API Scripter
By the way, in this code: on('clicked:calcdmg', (info) => { getAttrs(["damagerisk"], function(values) { startRoll("&{template:simple} {{name=Risk}} {{rolldamage=[[[[floor(@{damagerisk})]]d6s>5]]}}", (results) => { }); }); }); there's a getAttrs you don't need. So that should probably be: on('clicked:calcdmg', (info) => { startRoll("&{template:simple} {{name=Risk}} {{rolldamage=[[[[floor(@{damagerisk})]]d6s>5]]}}", (results) => { finishRoll(results.rollId) }); }); That said, unless you plan to do something extra with this roll, it looks to me that no sheet worker as needed, and you could change your action button to a roll button: <button type="roll" name="roll_calcdmg" value="&{template:simple} {{name=Risk}} {{rolldamage=[[[[floor(@{damagerisk})]]d6s>5]]}}">Damage</button> The various setAttrs and if statements in your earlier worker could be optimised. At present, if you have dmgboxhit = 0, a setAttrs will be fired twice. The first one will run, then this will overwrite it. setAttrs is a slow operation, and its best to always write your workers to only use it once. You can store what goes in the setAttrs in a javascript object, like this: const output = {}; // create the javascript object // use if else to ensure only one branch of the if statement is run if(dmgboxhit == 0) { output.damagerisk = 0; } else if (values.dmgcrt >= rollover) { output.damagerisk = rollover + dmgcrt; } else if(values.dmgcrt < rollover) { output.damagerisk = dmgcrt * 2; } setAttrs(output);