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

Simple Sheet Worker not working?

1549319071
Richard T.
Pro
Marketplace Creator
Sheet Author
Compendium Curator
Dipping a toe into sheet-workers with a new Mouse Guard sheet.  Trying to do a condition list with a kind of mixed behavior of checkboxes and radio. A character can have any arrangement of bad conditions. What I'd like to do is that by checking any bad condition, the sheetworker unchecks the "Healthy" box. And accordingly, if the player checks the "Healthy" box, it unchecks every other condition.  However... I can't even get the event listener to output to the console! T_T <script type="text/worker">     //Condition logic     on("change:healthy", function(eventInfo) {         console.log("Healthy clicked");         if (eventInfo.newValue=="on") {             setAttrs(attr_hungry, 0);             setAttrs(attr_angry, 0);             setAttrs(attr_tired, 0);             setAttrs(attr_injured, 0);             setAttrs(attr_sick, 0);         }     } </script> At first I was thinking I'd use the button listener, but looking at the documentation, it seems to want me to name the buttons to "act_<name>", which I imagine doesn't get me an attribute? Anyway, I figured changing the attribute would go backwards and express itself in the charactersheet, which it does if I go to the attributes tab in the character sheet.  Anyway, the console.log doesn't trigger, so trying to figure out how I've already botched a basic bit of script.  This is the bit of html for the checkboxes as well in case the problem lies there.          <div class="popout">             <h1>Conditions</h1>             <div class="flexrow"><h2>Healthy</h2><input type="checkbox" class="checkcondition" name="attr_healthy"/><span></span></div>             <div class="flexrow"><h2>Hungry/Thirsty</h2><input type="checkbox" class="checkcondition" name="attr_hungry"/><span></span></div>             <div class="flexrow"><h2>Angry (Ob 2 Will)</h2><input type="checkbox" class="checkcondition" name="attr_angry"/><span></span></div>             <div class="flexrow"><h2>Tired (Ob 3 Health)</h2><input type="checkbox" class="checkcondition" name="attr_tired"/><span></span></div>             <div class="flexrow"><h2>Injured (Ob 4 Health)</h2><input type="checkbox" class="checkcondition" name="attr_injured"/><span></span></div>             <div class="flexrow"><h2>Sick (Ob 4 Will)</h2><input type="checkbox" class="checkcondition" name="attr_sick"/><span></span></div>         </div>
1549322180

Edited 1549322311
Natha
KS Backer
Sheet Author
API Scripter
setAttrs parameter should be a json object. So you should probably try:     //Condition logic     on("change:healthy", function(eventInfo) {         console.log("Healthy clicked");         if (eventInfo.newValue=="on") {             setAttrs({attr_hungry: 0, attr_angry: 0, attr_tired: 0,attr_injured: 0, attr_sick: 0}); } });
1549323169
Finderski
Plus
Sheet Author
Compendium Curator
Natha said: setAttrs parameter should be a json object. So you should probably try: &nbsp; &nbsp; //Condition logic &nbsp; &nbsp; on("change:healthy", function(eventInfo) { &nbsp; &nbsp; &nbsp; &nbsp; console.log("Healthy clicked"); &nbsp; &nbsp; &nbsp; &nbsp; if (eventInfo.newValue=="on") { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setAttrs({attr_hungry: 0, attr_angry: 0, attr_tired: 0,attr_injured: 0, attr_sick: 0}); } }); Important: Note the closing ) in Natha's example the very last line in your code was missing that. Also, if you are not able to get the console.log to output that typically means you have a syntax error somewhere in your sheet worker, so if you look in your console log you'll likely see that referenced. One thing I've found helpful in trying to track down syntax errors is to put my sheetworker code in a syntax validator; the one I use is:&nbsp;<a href="http://esprima.org/demo/validate.html" rel="nofollow">http://esprima.org/demo/validate.html</a>
1549324016
Richard T.
Pro
Marketplace Creator
Sheet Author
Compendium Curator
Awesome, thanks guys. These brackets/parenthesis/semi colons kill me. I'll try out the validator in the future!&nbsp; And for future reference, you do indeed drop the 'attr_' from the attributes. I was testing it back and forth trying to figure out where it's necessary but I don't think its necessary anywhere.&nbsp;
1549324710
Finderski
Plus
Sheet Author
Compendium Curator
Richard T. said: Awesome, thanks guys. These brackets/parenthesis/semi colons kill me. I'll try out the validator in the future!&nbsp; And for future reference, you do indeed drop the 'attr_' from the attributes. I was testing it back and forth trying to figure out where it's necessary but I don't think its necessary anywhere.&nbsp; It's not. &nbsp;And also, as a reminder, when doing the on(change: thing, your attribute names are all lowercase, but when doing the getAttrs they are whatever case you used in the html. That can also cause problems, sometimes.
1549356270
Natha
KS Backer
Sheet Author
API Scripter
Richard T. said: And for future reference, you do indeed drop the 'attr_' from the attributes.&nbsp; Oh yes, sorry I missed that.