I was looking to implement a simple button that will reduce multiple other attributes by 1 point. Is this possible? I've been unable to find any information on how one might go about it.
I was looking to implement a simple button that will reduce multiple other attributes by 1 point. Is this possible? I've been unable to find any information on how one might go about it.
Yes, you can do this with creating an action button, that when pressed, triggers a sheetworker that does the changes.
<button type="action" name="act_reduce">
The type="action" version of the button on roll20 isn't that well known or documented, but there is a example of how action buttons can be used for swapping between pages that should help somewhat.
I haven't made any sheets with an action button to change stats, nor had the time so far to track down examples of sheets that uses them.
Edit: Typo fixed, thanks GiGs!
Lets's say you created an action button like the above, named reduce, here's an example worker that reduces a bunch of defined attributes by 1 each, when the button is clicked.
on('clicked:reduce', function() { // make an array of the attributes you plan to adjust, for ease of use later const attributes = ['list of attributes to adjust']; getAttrs(attributes, function(values) { const settings = {}; // make a variable to hold the changed attributes // loop through the attributes, get the value, then subtract 1 attributes.forEach(att => { // in each go through the loop, "att" becomes the next attribute let tempattribute = +values.att || 0; tempattribute -= 1; // store the changed attribute in the settings variable: settings[att] = tempattribute; }): // save the updated attributes to the sheet setAttrs(settings); }); });
I created a wiki page for the different types of uses for <button> in chracter sheet creation, and included the above example.
Nice! I noticed a small syntax error in the code above and fixed it here and on the wiki.
I should mention I used simplified code in that example for instructional purposes. But it might still be a bit heavy for a more general instructional example.
GiGs said:
I added a simpler example of adding 1 to a single attribute, as a better instruction to newbies.
Thanks!
I also made some improvements to the Building Char Sheets article, and added a link to the Button page in the relevant place.
Now a few things there should be worded a bit more clearly than before.