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

Custom sheet: button not triggering sheetworker script

Aloha! Been working on a custom sheet and actually learning a lot by building it from the ground up, but I'm still figuring out sheetworkers and one particular problem just doesn't seem to be solvable by my smoothbrain efforts. The goal is to have a button on the sheet: when pressed, a roll is made and depending on the outcome, an attribute is raised or lowered by 1 point - with a range of 0 - 4. The button appears fine: it's clickable but nothing happens when it's pressed. My other sheetworker scripts all function correctly The button reads as such: &lt;button style="background-image: url(<a href="https://github.com/LewisDTC/AnimeTemplateProject/raw/main/san-00.png" rel="nofollow">https://github.com/LewisDTC/AnimeTemplateProject/raw/main/san-00.png</a>); position: absolute; left: 175px; top: 70px; background-size: 80px 80px; background-repeat: no-repeat; width: 70px; height: 70px; border: none; outline: none; background-color: transparent;" type="action" name="stability_roll"&gt;&lt;/button&gt; My update script is split into three sections: I know that it's not efficient, but since I couldn't get the thing working I broke it down to try and troubleshoot it: on('clicked:stability_roll', function() { &nbsp; &nbsp; getAttrs(['stability, willpower_mod'], function(values) &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let roll = RandomInteger[{1, 20}]; &nbsp; &nbsp; &nbsp; &nbsp; let stability = parseInt(values.stability)||0; &nbsp; &nbsp; &nbsp; &nbsp; let willpower = parseInt(values.Willpower_Mod)||0; &nbsp; &nbsp; &nbsp; &nbsp; let result = parseInt(roll+stability+willpower)||0; &nbsp; &nbsp; &nbsp; &nbsp; if (result &gt;= 10) &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; newstability =&nbsp;stability + 1&nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; else &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; newstability = stability - 1 &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setAttrs({stability: newstability}); &nbsp; &nbsp; }); }); // Restrain Stability to Minimum on("change:stability", function() { &nbsp; &nbsp;getAttrs(["stability"], function(values) { &nbsp; &nbsp; &nbsp; &nbsp; let stability = parseInt(values.stability)||0; &nbsp; &nbsp; &nbsp; &nbsp; if (stability &lt; 0) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setAttrs({&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stability: 0&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; } else { &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; }); }); // Restrain stability to Maximum on("change:stability", function() { &nbsp; &nbsp;getAttrs(["stability"], function(values) { &nbsp; &nbsp; &nbsp; &nbsp; let stability = parseInt(values.stability)||0; &nbsp; &nbsp; &nbsp; &nbsp; if (stability &gt;= 5) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setAttrs({&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stability: 4&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; } else { &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; }); }); The variables used are: attr_stability attr_Willpower_Mod So uh... anyone have any idea what's wrong here?
1611579997

Edited 1611580285
GiGs
Pro
Sheet Author
API Scripter
You button isn't named correctly. Action buttons need to start with act_ , so it should be something like &lt;button style="background-image: url(<a href="https://github.com/LewisDTC/AnimeTemplateProject/raw/main/san-00.png" rel="nofollow">https://github.com/LewisDTC/AnimeTemplateProject/raw/main/san-00.png</a>); position: absolute; left: 175px; top: 70px; background-size: 80px 80px; background-repeat: no-repeat; width: 70px; height: 70px; border: none; outline: none; background-color: transparent;" type="action" name="act_stability"&gt;&lt;/button&gt; I dropped the _roll of the end, because there is a problem with action button names containing a second underscore if they are inside a repeating section. So it's a good idea to generally avoid extra underscores on action buttons, just to get in the habit. Here's code for your sheet worker so you don't need extra ones (with updated name): on('clicked:stability', function() { &nbsp; &nbsp; getAttrs(['stability, willpower_mod'], function(values) &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let roll = Math.floor(Math.random()*20) +1; &nbsp; &nbsp; &nbsp; &nbsp; let stability = parseInt(values.stability)||0; &nbsp; &nbsp; &nbsp; &nbsp; let willpower = parseInt(values.Willpower_Mod)||0; &nbsp; &nbsp; &nbsp; &nbsp; let result = roll + stability + willpower; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;let newstability; &nbsp; &nbsp; &nbsp; &nbsp; if (result &gt;= 10) &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; newstability =&nbsp;Math.min(stability + 1, 4); &nbsp; &nbsp; &nbsp; &nbsp; } else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; newstability = Math.max(stability, 0); &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setAttrs({stability: newstability}); &nbsp; &nbsp; }); }); I replaced your randomInteger function with the math.random() method. If you have created your own randomInteger function you can put it back - but the randomInteger function referred to in roll20 documentation doesnt work in sheet workers. Its an API script function. So here we have to use Math.random(). Note that you dont need parseInt in your arithmetic, since we knoe they are all numeric already. You can use Math.max(number, number) to take the largest value of a set of numbers, and Math.min to take the lowest value of a set of numbers. Using these you can constrain your results so they never go above 4 or below 0.
1611580264

Edited 1611580359
GiGs
Pro
Sheet Author
API Scripter
You can streamline this &nbsp;&nbsp;&nbsp;&nbsp;let newstability; &nbsp;&nbsp;&nbsp;&nbsp;if (result &gt;= 10) &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; newstability =&nbsp;Math.min(stability + 1, 4); &nbsp; &nbsp; &nbsp; &nbsp; } else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; newstability = Math.max(stability, 0); &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp;&nbsp; using a ternary operator , to this let newstability = (result &gt;= 10) ? Math.min(stability + 1, 4) : Math.max(stability, 0);
Cheers GiGs! Appreciate both the help and also you taking the time to explain. Sheetworkers are a step further than I've gone with Roll20 so far so it's a pretty steep learning curve, but I'm piecing things together bit by bit thanks to the community.
1611581460
GiGs
Pro
Sheet Author
API Scripter
You're welcome. Sheet workers do have a bit of a learning curve, good luck!
1611643412
vÍnce
Pro
Sheet Author
Why can't action buttons actually be used to make a roll?&nbsp; And Why can't regular sheet roll buttons be detected by sheetworkers? Ugh. Sorry, just complaining out loud.
1611646755
GiGs
Pro
Sheet Author
API Scripter
∇ince said: Why can't action buttons actually be used to make a roll?&nbsp; And Why can't regular sheet roll buttons be detected by sheetworkers? Ugh. Sorry, just complaining out loud. I'm with you there, I wish you could do both.&nbsp;