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

Checkbox to change a number? (script help)

1781649149

Edited 1781649192
I am coding illiterate and trying to change some code a friend helped me with. I have several categories of check boxes that correspond to different dice sizes for rolls. A dice roll consists of two dice: one determined by a number value in that skill (like speed), and another determined by checkboxes which indicate the other die size (called stress). If no boxes are checked, the number should be 10. If the "d8stress1" box is checked, then 8. If the "d6stress1" box is checked, then 6. If the "helpless" box is checked, then 4. My best understanding is that my friend used a script to alter the number that is rolled. This number is called "invisiblestress". A button to roll speed looks like this: <button name="roll_speedroll" value="/roll 1d@{speed} + 1d@{invisiblestress} + ?{Add a +1?|None, 0|+1, 1|+2, 2|+3, 3}" data-sm-id="67" type="roll" class="sm-prop sm-roll" style="left: 109px; top: 883px; width: 83px; height: 33px;"></button> The current working script looks like this (but does not include the helpless d4): <!-- Roll20 Sheet Workers below --> <input type="hidden" name="attr_invisiblestress" value=10> <script type="text/worker"> on("change:d8stress1 change:d6stress1", function() { getAttrs(["d8stress1", "d6stress1"], function(values) { const d8 = parseInt(values.d8stress1) || 0; const d6 = parseInt(values.d6stress1) || 0; const result = 10 - (d8 * 2) - (d6 * 2); setAttrs({ invisiblestress: result }); }); }); </script> How do I edit this to have the helpless checkbox make the result equal 4?
1781655379

Edited 1781655467
vÍnce
Pro
Sheet Author
You probably need something like this (assumed that the helpless checkbox attribute was actually called "helpless", and that the checkboxes are value="1"... edit as needed.) <input type="number" name="attr_invisiblestress" value="10"> <script type="text/worker"> on("change:d8stress1 change:d6stress1 change:helpless", function() {     getAttrs(["d8stress1", "d6stress1", "helpless"], function(values) {         const d8 = parseInt(values.d8stress1) || 0;         const d6 = parseInt(values.d6stress1) || 0;         const d4 = parseInt(values.helpless) || 0;         const result = 10 - (d8 * 2) - (d6 * 2) - (d4 * 2);         setAttrs({             invisiblestress: result         });     }); });
vÍnce said: You probably need something like this (assumed that the helpless checkbox attribute was actually called "helpless", and that the checkboxes are value="1"... edit as needed.) <input type="number" name="attr_invisiblestress" value="10"> <script type="text/worker"> on("change:d8stress1 change:d6stress1 change:helpless", function() {     getAttrs(["d8stress1", "d6stress1", "helpless"], function(values) {         const d8 = parseInt(values.d8stress1) || 0;         const d6 = parseInt(values.d6stress1) || 0;         const d4 = parseInt(values.helpless) || 0;         const result = 10 - (d8 * 2) - (d6 * 2) - (d4 * 2);         setAttrs({             invisiblestress: result         });     }); }); The attribute is indeed called helpless, and value = 1. This is my checkbox for helpless: <input name="attr_helpless" data-sm-id="46" type="checkbox" value="1" class="sm-prop sm-checkbox" style="left: 892px; top: 753px; width: 35px; height: 40px;"> I input the code and am only able to get the result of 6 for some reason. Any ideas?
1781665267
vÍnce
Pro
Sheet Author
Just to be clear,  you replaced the original sheetworker, correct?  Also, make sure there is a closing tag at the end of your sheetworker ie </script>  I accidentally left it off of my pasted code. ;-(
vÍnce said: Just to be clear,  you replaced the original sheetworker, correct?  Also, make sure there is a closing tag at the end of your sheetworker ie </script>  I accidentally left it off of my pasted code. ;-( I did forget to end the closing tag! That was it, it seems to work now! Thank you for your help!