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

One button to modify several attributes?

1578809997
Robert R.
Plus
Marketplace Creator
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.
1578811888

Edited 1578812962
Andreas J.
Forum Champion
Sheet Author
Translator
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 !
1578812775
GiGs
Pro
Sheet Author
API Scripter
Just a quick typo correction (quote in the wrong place) <button type="action" name="act_reduce">
1578813281

Edited 1578818672
GiGs
Pro
Sheet Author
API Scripter
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); }); });
1578817374
Andreas J.
Forum Champion
Sheet Author
Translator
I created a wiki page for the different types of uses for <button> in chracter sheet creation, and included the above example.
1578818650

Edited 1578818841
GiGs
Pro
Sheet Author
API Scripter
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.
1578819304
GiGs
Pro
Sheet Author
API Scripter
I added a simpler example of adding 1 to a single attribute, as a better instruction to newbies.
1578821165
Andreas J.
Forum Champion
Sheet Author
Translator
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.
1578858127
Robert R.
Plus
Marketplace Creator
Wow thanks for the excellent help everyone!  I don't know how I overlooked it in the wiki, but I am definitely going to be utilizing it.  Very very appreciated.