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

[Script] Reset attribute value on button click

This should be a fairly simple script from what I can tell, but me having zero experience in JS means I'll be bashing my head against the wall for the foreseeable future as I try random keypresses, hoping they'll turn into legible code. I have 2 text fields on my character sheet, one with the attribute GlobalModifier and another with the attribute GlobalMultiplier. I want a script that when ANY "roll" button is pressed, the value of these two attributes is reset to a certain value (GlobalModifier: 0, GlobalMultiplier: 1).  I need this as part of my macro. Currently I'm using the regular pop-up boxes which ask players to input a modifier/multiplier to their roll, but this is starting to get a bit irritating, so I figured having a text box on the character sheet where the players can enter any modifiers/multipliers to their next roll would be less obtrusive. I just want to make sure that the text fields reset back to their default values after the macro is executed so that the players don't accidentally roll something with an incorrect modifier if they forget to delete it (I figure having this happen after a roll button is clicked would be easiest rather than checking for rolls etc, but I may be wrong). Could someone help me out with this script? If you need any other info about the character sheet etc, let me know. Appreciate any help!
1563205338
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
So, this isn't possible as you're probably thinking of it. Character sheet sheetworkers can't respond to a roll button being pressed, and the API can't either. The API can respond to chat messages. So, you could have an API script respond to a specific field showing in the outputted roll template that it would then react to. If this is for a personal project, I'd probably recommend just using chatsetattr to handle this rather than coding something specially for it. If this is for a sheet you plan to submit to the repo though, I'd say you'll need to rethink how the reset is happening as sheets requiring the API are not well accepted in the repo.
I see. Thank you. I've had a look at ChatSetAttr (yes, it's for a personal project) and I managed to execute the command in chat. However, I had to specify the character name specifically. I don't know how to "call" for the name for the particular character sheet it's rolled from, i.e. have it come up automatically. So what I'm thinking is something along the lines of… New script that looks for the term "rolled" to appear as part of a template, find out which character sheet it came from, change the attributes of that character sheet (as mentioned previously). Would that work?