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 .
×

repeatingSum don't trigger

1637316240

Edited 1637406550
Hello there, I started coding my own sheet 3 days ago and I'm stuck (I'm not a developper, still try to understand this). I want to calculate the total weight of equipments, but I don't success to print it on my sheet, when I change something it just do nothing. I add a console.log but there is nothing heppened when I change value on my sheet in the firefox console, may I miss something ? The code : &lt; div class = "grid-sac" &gt; &nbsp; Sac &nbsp; &nbsp; &lt; fieldset class = "repeating_equipements" &gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt; div &gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &lt; input type = "text" class = "sheet-objet-nom" spellcheck = "false" name = "attr_equipement" placeholder = "Objet" /&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt; input type = "number" class = "sheet-number-long" spellcheck = "false" name = "attr_equipement_nombre" placeholder = "Nb" /&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt; input type = "number" class = "sheet-number-long" spellcheck = "false" name = "attr_equipement_poids" placeholder = "Kg" /&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/ div &gt; &nbsp; &nbsp; &lt;/ fieldset &gt; &nbsp; &nbsp; Poids total &nbsp; &nbsp; &lt; input type = "number" class = "sheet-objet-long" spellcheck = "false" name = "attr_poids_total" placeholder = "Poids total" /&gt; &lt;/ div &gt; &lt; script type = "text/worker" &gt; &nbsp; &nbsp; const repeatingSum = (destinations, section, fields) =&gt; { &nbsp; &nbsp; &nbsp; &nbsp; if (!Array.isArray(destinations)) destinations = [destinations.replace(/\s/g, '').split(',')]; &nbsp; &nbsp; &nbsp; &nbsp; if (!Array.isArray(fields)) fields = [fields.replace(/\s/g, '').split(',')]; &nbsp; &nbsp; &nbsp; &nbsp; getSectionIDs(`repeating_${section}`, idArray =&gt; { &nbsp; &nbsp; &nbsp; &nbsp; const attrArray = idArray.reduce((m, id) =&gt; [...m, ...(fields.map(field =&gt; `repeating_${section}_${id}_${field}`))], []); &nbsp; &nbsp; &nbsp; &nbsp; getAttrs([...attrArray], v =&gt; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const getValue = (section, id, field) =&gt; v[`repeating_${section}_${id}_${field}`] === 'on' ? 1 : parseFloat(v[`repeating_${section}_${id}_${field}`]) || 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const commonMultipliers = (fields.length &lt;= destinations.length) ? [] : fields.splice(destinations.length, fields.length - destinations.length); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const output = {}; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; destinations.forEach((destination, index) =&gt; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; output[destination] = idArray.reduce((total, id) =&gt; total + getValue(section, id, fields[index]) * commonMultipliers.reduce((subtotal, mult) =&gt; subtotal * getValue(section, id, mult), 1), 0); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log(output); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setAttrs(output); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; }; &nbsp; &nbsp; on('change:repeating_equipements remove:repeating_equipements', function() { &nbsp; &nbsp; &nbsp; &nbsp; repeatingSum("poids_total","equipements",["equipement_poids","equipement_nombre"]); &nbsp; &nbsp; }); &nbsp; &lt;/ script &gt; CSS .grid-equipement { &nbsp; &nbsp; display : grid ; &nbsp; &nbsp; grid-auto-columns : minmax ( 10% , auto ); &nbsp; &nbsp; grid-auto-rows : minmax ( 10% , auto ); &nbsp; &nbsp; gap : 2% ; &nbsp; &nbsp; padding-block: 1% ; } .grid-sac { &nbsp; &nbsp; display : grid ; &nbsp; &nbsp; border : 1px solid rgba ( 26 , 27 , 28 , 0.1 ); &nbsp; &nbsp; grid-column : 1 / 4 ; &nbsp; &nbsp; grid-row : 2 ; } My full code (still working on it) : <a href="https://github.com/Mihawk59/AventuresV2.git" rel="nofollow">https://github.com/Mihawk59/AventuresV2.git</a> <a href="https://github.com/Mihawk59/AventuresV2.git" rel="nofollow">https://github.com/Mihawk59/AventuresV2.git</a> Thank you ! *sorry for mistakes, english isn't my mother tongue*
1637350147

Edited 1637350487
vÍnce
Pro
Sheet Author
Try setting your auto calculated attribute in html to "readonly". &lt; input type = "number" class = "sheet-objet-long" spellcheck = "false" name = "attr_poids_total" placeholder = "Poids total" readonly /&gt; Given this is a number field, there's not need for a placeholder , I would set a default value="0" and I'm not sure if the spellcheck option would work here either... Not an issue here(because it is consistent), but "equipements" is misspelled.&nbsp; "Could" be an issue/point of confusion down the road if you ever use the proper spelling for more coding or macro usage.
1637364128

Edited 1637365546
Oosh
Sheet Author
API Scripter
vÍnce said Not an issue here(because it is consistent), but "equipements" is misspelled.&nbsp; "Could" be an issue/point of confusion down the road if you ever use the proper spelling for more coding or macro usage. Errr... If it was in English, it would be misspelled. The rest of the attribute names didn't bother you? :) @OP: I just tested the code you posted and it works fine (I added an extra log to make sure the handler is triggering) I can't see your full code (maybe the repo is private?), but if you have any error in your javascript, the entire block will fail - so if you're getting nothing in the console, you probably have an error somewhere else in your code. EDIT - I found the repo, maybe the folder name had changed (the link above is a 404). Anyway, I'd recommend you take your code out of the &lt;script&gt; block while you're editing, and place it in a .js file so vsCode can lint properly. It's just a bunch of simple syntax errors that's causing your script block to fail: You're also declaring 'newrowid' after assigning it a value, which is leaning on variable hoisting in a pretty nasty way. But that's a separate issue :)
1637368214
vÍnce
Pro
Sheet Author
Oosh said: Errr... If it was in English, it would be misspelled. The rest of the attribute names didn't bother you? :) lol.&nbsp; Move along. Nothing to see here... ;-)
Ahah yes I write in French ;-p I follow your tips and it work well now thank you both ! It looks like when I'm coding I don't see the little mistakes like this even if I check 100 times -_-' Indeed it's easier to code in a separate file to see it, I'll remember that ;-)