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

Execute script on click on a roll button

1545132250

Edited 1545138030
Hi, I can't find any hint on the forum for this particular point. It seems trivial but I'm unable to do it... I get this script working perfectly fine : on("change:bet_display_impact", function() {     getAttrs(["pp_current", "mp_current", "sp_current", "pp_bet", "mp_bet", "sp_bet"], function(values) {       setAttrs({         pp_current: values.pp_current - values.pp_bet,         mp_current: values.mp_current - values.mp_bet,         sp_current: values.sp_current - values.sp_bet       });     });   }); It operate on a checkbox and execute as intend. But I want this script to work when a roll button is clicked. Any hint folks ?
1545169923
GiGs
Pro
Sheet Author
API Scripter
Unfortunately, it's just not possible. Roll buttons only print to chat, and chat can't trigger changes to character sheets (unless using API scripts). You could use CSS to style the checkbox so it looks like a button. You could also have the script set the checkbox value back to 0, so it is ready to be clicked again immediately after being clicked (adding  bet_display_impact: 0 to the setAttrs function).
Thanks for the information. I was thinking an equivalent of onClick function exists. Just a bit of CSS to skin the checkbox will be fine.
1545176445
Caden
Forum Champion
Sheet Author
API Scripter
Compendium Curator
It can't be done with the roll button but it can be done with an action button . You could do a button that does the roll you need and a separate one that does the setAttrs.  <button type="action" name="act_activate">Activate!</button> on("clicked:activate", function() {   console.log("Activate button clicked"); });
Thanks Cassie, it will be more efficient than skining a checkbox ! Just a question : knowing that my rule system doesn't need to roll dices but just do basic math (sum of multiple attrs defined by inputs), can I use this action button to display the result in the chat ? Maybe with a script ? Or the roll button is solely able to do that ?
1545214488

Edited 1545214519
Natha
KS Backer
Sheet Author
API Scripter
Akefal said: Thanks Cassie, it will be more efficient than skining a checkbox ! Just a question : knowing that my rule system doesn't need to roll dices but just do basic math (sum of multiple attrs defined by inputs), can I use this action button to display the result in the chat ? Maybe with a script ? Or the roll button is solely able to do that ? Action button/sheet workers won't be able to output anything to chat. You'll need a roll button or an API script for that. EDIT: PS: and unfortunately, for now, action buttons can't be called as a character ability/"chat button".
Thanks Natha, and all of you guys. I used your solutions to figure out a workaround. It would be better with just the click on the roll button but using action buttons do the trick.