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 Workers]

Are sheet workers triggered by changes in radio buttons? I have a (cycling) radio button with the values of "0.5" and "1".  In the sheet workers is suppose to multiply by a set number, and then add some other numbers.  Like so: //awareness on("change:awareness1 change:awareness2 change:awareness3 change:awareness4 change:per_total sheet:opened", function() { getAttrs(["awareness1", "awareness2", "awareness3", "awareness4", "per_total"], function(values) {         setAttrs({             awareness: (+values.per_total * +values.awareness1) + +values.awareness2 + +values.awareness3 + +values.awareness4     }); }); }); But only the additions are being working. Anyone know why that is?
1554403708

Edited 1554403919
GiGs
Pro
Sheet Author
API Scripter
If the radio buttons have an attr name, it should be triggered. If the thing I suggest below fails, can you post your radio button html? I have found sometimes putting your calculation in the setAttrs line can fail, depending on syntax  (especially if type coercion is occurring). Try doing your calculation before that: on("change:awareness1 change:awareness2 change:awareness3 change:awareness4 change:per_total sheet:opened", function() { getAttrs(["awareness1", "awareness2", "awareness3", "awareness4", "per_total"], function(values) {         let awareness = (+values.per_total * +values.awareness1) + +values.awareness2 + +values.awareness3 + +values.awareness4;         setAttrs({             awareness:awareness     }); }); }); If that doesnt work, you'll either have to grab each value individually and check whether it's working properly, or change the type-coercion method from +value to something else. I do both here: on("change:awareness1 change:awareness2 change:awareness3 change:awareness4 change:per_total sheet:opened", function() { getAttrs(["awareness1", "awareness2", "awareness3", "awareness4", "per_total"], function(values) {         let pertotal = values.per_total*1||0; console.log("============= per Total = " + pertotal); let awareness = pertotal * values.awareness1*1 + values.awareness2*1 + values.awareness3*1 + values.awareness4*1;         setAttrs({             awareness:awareness     }); }); }); This version lets you check the per_total value in browser console since that seems to be where the error is occurring. 
1554404349
GiGs
Pro
Sheet Author
API Scripter
I should have asked: does the sheetworker you listed print out a value? I was operating under the assumption that per_total is undefined, but that would fail completely. An alternative theory is that per_total it is always being treated as value 1. Whatever the case, we need to find out what value it is being treated as, so the second worker I posted above will help.  It also occurs to me that once your sheet worker is working, you are going to get answers involving decimal values some of the time. Shouldn't you be rounding off before you send to the character sheet? 
1554409130

Edited 1554409212
Coal Powered Puppet
Pro
Sheet Author
Html Awareness (Per) <div class="sheet-hold">     <textarea class="sheet-small sheet-talent" name="attr_awareness_notes"></textarea> <input type="number" name="attr_awareness" value="0"/> <td>     <div class="skill_radio">         <input type="radio" name="attr_awareness1" value="0.5" checked/>         <input type="radio" name="attr_awareness1" value="1" />             <span class="skill_radio untrained" style="font-family: 'Pictos'" ></span>             <span class="skill_radio trained" style="font-family: 'Pictos'">3</span>     </div> </td> <td><input type="checkbox" name="attr_awareness2" value="10" /></td> <td><input type="checkbox" name="attr_awareness3" value="10" /></td> <td>     <button type="roll" name="roll_awareness" value="&{template:rt} {{name= Awareness}} {{character= @{character_name} }} {{roll= [[(@{awareness}+?{Modifier|0}-1d100)/10]] degree(s) of success!}} {{notes= @{awareness_notes}}}">         <span class="skill_span" name="attr_awareness"></span>     </button> </td> <td><input type="checkbox" name="attr_awareness4" value="10" /></td> So, the first example didn't work. per_total is set by another sheet worker, and is a number between 1 and 100.
1554410042
GiGs
Pro
Sheet Author
API Scripter
At first glance, I cant see anything that would cause a problem in that html. Can you describe what exactly is happening? What is the error you are seeing? Also, can you post the per_total html and sheet worker too, please?
per_total on("change:per change:advancePer sheet:opened", function() { getAttrs(["per", "advancePer"], function(values) { setAttrs({ per_total: +values.per + +values.advancePer }); }); }); What happens: each check box add/removes +10, but the base number equals per_total
1554410451
GiGs
Pro
Sheet Author
API Scripter
Thanks. I meant, what is going wrong? is any awareness value being generated?
1554410550

Edited 1554410650
GiGs
Pro
Sheet Author
API Scripter
In your per_total sheet worker,  on("change:per change:advancePer sheet:opened", function() { should be on("change:per change:advanceper sheet:opened", function() { Give that a quick test and see if it works. Attributes in the on(change) event line need to be all lower case. Only that line should be lower case - all other advancePer should be with the upper case letter.
1554411116
GiGs
Pro
Sheet Author
API Scripter
Okay this is weird. The code you have listed is working for me. I created a sheet that looks like this:     Awareness <input type="number" name="attr_awareness" value="0" readonly /><br>     per <input type="number" name="attr_per" value="20"  /><br>     advancePer <input type="number" name="attr_advancePer" value="30"  /><br>     total <input type="number" name="attr_per_total" value="0" /><br/>     <div class="skill_radio">         <input type="radio" name="attr_awareness1" value="0.5" checked />         <input type="radio" name="attr_awareness1" value="1" />     </div>     <br/>     <input type="checkbox" name="attr_awareness2" value="10" /><br/>     <input type="checkbox" name="attr_awareness3" value="10" /><br/>     <input type="checkbox" name="attr_awareness4" value="10" /><br/>          <button type="roll" name="roll_awareness" value="&{template:default} {{name= Awareness}} {{character= @{character_name} }} {{roll= [[(@{awareness}+?{Modifier|0}-1d100)/10]] degree(s) of success!}} ">         <span class="skill_span" name="attr_awareness"></span>     </button>     <br/>     <script type="text/worker"> on("change:awareness1 change:awareness2 change:awareness3 change:awareness4 change:per_total sheet:opened", function() { getAttrs(["awareness1", "awareness2", "awareness3", "awareness4", "per_total"], function(values) {                    let awareness = (+values.per_total * +values.awareness1) + +values.awareness2 + +values.awareness3 + +values.awareness4;         setAttrs({             awareness:awareness     }); }); }); on("change:per change:advancePer sheet:opened", function() {     getAttrs(["per", "advancePer"], function(values) {         setAttrs({             per_total: +values.per + +values.advancePer         });     }); }); </script> It is working perfectly: the per_total is calculated, and is multipled by 1/2 or 1, depending on the radio button. The advance check boxes each add 10 to the total. Have you tried creating a new character and testing in there. It might be that you have corrupt data or multiple duplicate attributes oin the character you have been testing with.  If the error isn't fixed in a new character, what's happening?
No, a new character sheet did not fix it.   When plug a number into the perception attribute, the awareness number become the per total, no matter which awareness1 is checked.  the other inputs (awareness2, awareness 3, etc) function a expected.  I am using chrome, if that matters.
1554412322

Edited 1554412351
GiGs
Pro
Sheet Author
API Scripter
I'm using chrome too, so that shouldnt be an issue. Do you have another awareness1 attribute in your html anywhere? Do a search for it. If not, try this code for your awareness, and check the console to see what value its reporting. Make sure to select the 0.5 value, and then enter a perception value and see if the console reports the correct value (0.5). on("change:awareness1 change:awareness2 change:awareness3 change:awareness4 change:per_total sheet:opened", function() { getAttrs(["awareness1", "awareness2", "awareness3", "awareness4", "per_total"], function(values) {                    let awareness = (+values.per_total * +values.awareness1) + +values.awareness2 + +values.awareness3 + +values.awareness4;            let a1 = +values.awareness1;            console.log('========== awareness 1: ' + a1);         setAttrs({             awareness:awareness     }); }); });
Will do.  And thank you for some much personal help
1554451877
GiGs
Pro
Sheet Author
API Scripter
Happy to help :) Let us know if you are still having issues.
GiGs said: Do you have another awareness1 attribute in your html anywhere? Do a search for it. Oh for $^%('s sake!  God &%@#$, %^#*ing bull@74!  No, I did not have anothr "awareness1".  I had a whole other awareness sheet worker.  It works now.   Thank you for your help.  It got there eventually.
1554496034
GiGs
Pro
Sheet Author
API Scripter
That would explain it, hehe. 
1554497202
vÍnce
Pro
Sheet Author
Coal Powered Puppet said: Oh for $^%('s sake!  God &%@#$, %^#*ing bull@74!  Now your speaking a programming language I understand. ;-P
New problem: repeating field.&nbsp; I am getting Nan .&nbsp;&nbsp; Sheet worker: //basicskill on("change:repeating_basicskills:basicskillbox1 change:repeating_basicskills:basicskillbox2 change:repeating_basicskills:basicskillbox3 change:repeating_basicskills:basicskillbox4 change:repeating_basicskills:basicskillcharacteristic sheet:opened", function() { getAttrs(["repeating_basicskills_basicskillbox1", "repeating_basicskills_basicskillbox2", "repeating_basicskills_basicskillbox3", "repeating_basicskills_basicskillbox4", "repeating_basicskills_basicskillcharacteristic"], function(values) { let skill = Math.floor(+values.repeating_basicskills_basicskillcharacteristic * +values.repeating_basicskills_basicskillbox1) + +values.repeating_basicskills_basicskillbox2 + +values.repeating_basicskills_basicskillbox3 + +values.repeating_basicskills_basicskillbox4; setAttrs({ repeating_basicskills_basicskill:skill }); }); }); Console log CLICKED: radio/checkbox &lt;input type=​"radio" class=​"sheet-skill_radio sheet-trained" name=​"attr_-LbjNt_0yKpUL63o6cOX_repeating_basicskills_basicskillbox1" value=​"1" data-attrname=​"basicskillbox1"&gt;​ app.js?1554219501:551 input type radio value = "1" app.js?1554219501:551 Really updating character sheet values app.js?1554219501:551 Setting up repeating sections took until 8ms app.js?1554219501:551 Finding list of dirty attributes took until 9ms app.js?1554219501:551 Querytest took until 10ms app.js?1554219501:551 Attribute cache compliation took until 10ms app.js?1554219501:551 Set values (including auto-calcuating variables) took until 14ms app.js?1554219501:551 Took 15ms firebase.2.4.0.js:45 FIREBASE WARNING: Exception was thrown by user callback. Error: Firebase.update failed: First argument contains NaN in property 'campaign-3620296-GNf3z-qJtXmeHR6ja-eu6Q.char-attribs.char.-Lbj0wQvsSJpzVMKmtxA.-LbjMpFxmbVIrYOCQykz.current' at hg (<a href="https://app.roll20.net/assets/firebase.2.4.0.js:123:203" rel="nofollow">https://app.roll20.net/assets/firebase.2.4.0.js:123:203</a>) at <a href="https://app.roll20.net/assets/firebase.2.4.0.js:126:168" rel="nofollow">https://app.roll20.net/assets/firebase.2.4.0.js:126:168</a> at Fb (<a href="https://app.roll20.net/assets/firebase.2.4.0.js:28:656" rel="nofollow">https://app.roll20.net/assets/firebase.2.4.0.js:28:656</a>) at jg (<a href="https://app.roll20.net/assets/firebase.2.4.0.js:126:134" rel="nofollow">https://app.roll20.net/assets/firebase.2.4.0.js:126:134</a>) at X.update (<a href="https://app.roll20.net/assets/firebase.2.4.0.js:258:369" rel="nofollow">https://app.roll20.net/assets/firebase.2.4.0.js:258:369</a>) at <a href="https://app.roll20.net/assets/app.js?1554219501:81:1876" rel="nofollow">https://app.roll20.net/assets/app.js?1554219501:81:1876</a> at c (<a href="https://app.roll20.net/assets/firebase.2.4.0.js:240:58" rel="nofollow">https://app.roll20.net/assets/firebase.2.4.0.js:240:58</a>) at <a href="https://app.roll20.net/assets/firebase.2.4.0.js:201:710" rel="nofollow">https://app.roll20.net/assets/firebase.2.4.0.js:201:710</a> at gc (<a href="https://app.roll20.net/assets/firebase.2.4.0.js:52:165" rel="nofollow">https://app.roll20.net/assets/firebase.2.4.0.js:52:165</a>) at cc (<a href="https://app.roll20.net/assets/firebase.2.4.0.js:30:216" rel="nofollow">https://app.roll20.net/assets/firebase.2.4.0.js:30:216</a>) S @ firebase.2.4.0.js:45 (anonymous) @ firebase.2.4.0.js:52 setTimeout (async) gc @ firebase.2.4.0.js:52 cc @ firebase.2.4.0.js:30 bc @ firebase.2.4.0.js:29 Qi @ firebase.2.4.0.js:224 h.Ib @ firebase.2.4.0.js:238 h.Og @ firebase.2.4.0.js:240 Backbone.sync @ app.js?1554219501:81 save @ base.js?1552405209:7 syncedSave @ app.js?1554219501:552 (anonymous) @ app.js?1554219501:561 C.each.C.forEach @ base.js?1552405209:6 u.(anonymous function) @ base.js?1552405209:7 (anonymous) @ app.js?1554219501:561 firebase.2.4.0.js:123 Uncaught Error: Firebase.update failed: First argument contains NaN in property 'campaign-3620296-GNf3z-qJtXmeHR6ja-eu6Q.char-attribs.char.-Lbj0wQvsSJpzVMKmtxA.-LbjMpFxmbVIrYOCQykz.current' at hg (firebase.2.4.0.js:123) at firebase.2.4.0.js:126 at Fb (firebase.2.4.0.js:28) at jg (firebase.2.4.0.js:126) at X.update (firebase.2.4.0.js:258) at app.js?1554219501:81 at c (firebase.2.4.0.js:240) at firebase.2.4.0.js:201 at gc (firebase.2.4.0.js:52) at cc (firebase.2.4.0.js:30)
1554502269

Edited 1554502768
GiGs
Pro
Sheet Author
API Scripter
NaN means one of your attributes is not a number (it may be text, or empty) and you are trying to do number things with it (e.g. addition). So the first thing to check: does each attribute have a default value that is a number (including 0). If not, that's the the first thing to fix. Second thing: are any of the attributes autocalc fields? If so, sheet workers don't read them as numbers, they read then as a text formula and you'll get the NaN error when you try to do anything with them. The fix for that is replacing those autocalcs with sheet workers&nbsp; Thirdly, and this is a subtle one: can the attributes ever be empty? That is, no number, no text, nothing in the input at all? that can also cause an NaN error. A workaround for the last one, and similar errors is to include error checking in each attribute. When you call the attribute, append ||0, like (+values.repeating_basicskills_basicskillbox1 || 0) When the attribute is invalid, it will be replaced by the number 0, allowing the rest of the calculation to work. (Sometimes ||1 is better, like in multiplications.)&nbsp; If none of this fix your issue, you need to break down the sheet worker and examine the values of each attribute. Note: the code below deliberately does not use error checking (like adding ||0) because we want to find the error, not hide it. The worker below disables the setattrs function, and prints out the value of each attribute to console log: on("change:repeating_basicskills:basicskillbox1 change:repeating_basicskills:basicskillbox2 change:repeating_basicskills:basicskillbox3 change:repeating_basicskills:basicskillbox4 change:repeating_basicskills:basicskillcharacteristic sheet:opened", function() { getAttrs(["repeating_basicskills_basicskillbox1", "repeating_basicskills_basicskillbox2", "repeating_basicskills_basicskillbox3", "repeating_basicskills_basicskillbox4", "repeating_basicskills_basicskillcharacteristic"], function(values) {&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; let bsc = +values.repeating_basicskills_basicskillcharacteristic; let bsb1 = +values.repeating_basicskills_basicskillbox1; let bsb2 = +values.repeating_basicskills_basicskillbox2; let bsb3 = +values.repeating_basicskills_basicskillbox3; let bsb4 = +values.repeating_basicskills_basicskillbox4; console.log(`=============================== CHECKING VALUES: BSC = ${bsc}; BSB1 = ${bsb1}; BSB2 = ${bsb2}; BSB3 = ${bsb3}; BSB4 = ${bsb4};`); // note: that long ===== at the start is just to make it stand out in the console log /* &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;let skill = Math.floor(+values.repeating_basicskills_basicskillcharacteristic * +values.repeating_basicskills_basicskillbox1) + +values.repeating_basicskills_basicskillbox2 + +values.repeating_basicskills_basicskillbox3 + +values.repeating_basicskills_basicskillbox4; &nbsp; &nbsp; &nbsp; &nbsp; setAttrs({ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; repeating_basicskills_basicskill:skill &nbsp; &nbsp; }); */ }); }); You can check each value, and see if anything jumps out as wrong. Try changing each attribute and see what the console log reports. Let us know how you get on.
GiGs said: NaN means one of your attributes is not a number (it may be text, or empty) and you are trying to do number things with it (e.g. addition). Don't sass me!&nbsp; I happen to know NaN stands for North Atlantic Nihilists, a not-so-secret conspiracy group bent on world domination through the theft of left shoes.&nbsp; This stupid code just sent them a message saying I am a good target and now I will the the shoe-less Coal Powered Puppet any day now! ...yeah, I figure that much out.&nbsp; One of my sources was a select dropdown with "@{attribute}" as a value.&nbsp; I set up an if/else and its all good.&nbsp; Thanks!
1554503113
GiGs
Pro
Sheet Author
API Scripter
hehe, I always target my replies at people who have no knowledge about programming whatsoever (unless I know their level of familiarity of course). I do worry that it might sometimes sound condescending.
Please continue to treat me as some who knows nothing about coding.&nbsp; I know just enough to be dangerous, mostly to myself. You help has allowed/made it possible for me to run my game tomorrow, so thank you very much.&nbsp; My sheet works!&nbsp;&nbsp;
1554503247
vÍnce
Pro
Sheet Author
GiGs said: hehe, I always target my replies at people who have no knowledge about programming whatsoever Thanks a lot GiGs
1554503701
GiGs
Pro
Sheet Author
API Scripter
Vince said: GiGs said: hehe, I always target my replies at people who have no knowledge about programming whatsoever Thanks a lot GiGs lol, you're welcome. (I genuinely laughed out loud.) And glad to be of help CPP. I've borrowed a lot of your html/css in my character sheets, so its nice to be able to return the favour.