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

[Sheet Worker Script] On change, cancel the change?

1510772447
Davemania
KS Backer
Sheet Author
API Scripter
Is it possible, on change, to check the value of eventInfo.newValue and based on the check, cancel or undo the change? Or is there another method of some simple error/dependency checking for attributes? Here is my scenario: <select name="attr_charTypeA">         <option value="Star">Star</option>         <option value="CoStar">Co-Star</option>         <option value="Grunt">Grunt</option> </select> <select name="attr_charTypeB">         <option value="Civilian">Citizen</option>         <option value="Police">Police</option>         <option value="Military">Military</option>         <option value="NationalGuard">National Guard</option>         <option value="Survivor">Survivor</option>         <option value="Ganger">Ganger</option> </select> If charTypeB is Police,Military, or NationalGuard then I want to enforce that charTypeA can only be Grunt. I was able to accomplish this: <script type="text/worker">     on("change:chartypeb", function(eventInfo) {         if (eventInfo.newValue == "Police" || eventInfo.newValue == "Military" || eventInfo.newValue == "NationalGuard") {             setAttrs({                 charTypeA: "Grunt";             });         }     }); </script> But how do I prevent selecting Star or CoStar after charTypeB has been set to Police, Military or NationalGuard? This didn't seem to work:     on("change:chartypea", function(eventInfo) {         if (eventInfo.newValue == "Star" || eventInfo.newValue == "CoStar") {             getAttrs(["chartypeb"], function(values) {                 if (values.chartypeb == "Police" || values.chartypeb == "Military" || values.chartypeb == "NationalGuard") {                     setAttrs({                         charTypeA: "Grunt";                     });                 }             });         }     }); Thanks for taking a look!
1510779727
Lithl
Pro
Sheet Author
API Scripter
eventInfo.previousValue will tell you what the attribute changed from . You can simply set it back to that value to undo it.
1510780385
Davemania
KS Backer
Sheet Author
API Scripter
That is essentially what I am trying to do in that last code block. By checking the value of chartypeb, I know that I want chartypea to be set to "Grunt" without having to look at what it was. However, it didn't seem to work and I don't know how to get feedback from or debug the sheet worker script (this is my first attempt at utilizing it).
1510787203
Jakob
Sheet Author
API Scripter
Try this                     setAttrs({                         charTypeA: "Grunt"                     }); There should not be a semicolon at the end of a line in an object literal.
1510842749
Davemania
KS Backer
Sheet Author
API Scripter
Jakob said: There should not be a semicolon at the end of a line in an object literal. And that did it. I must have over-corrected at some point.Thanks!