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] Multiplying in repeating Field

I am trying to get a sheet worker to do multiplication inside a repeating field, and its not being nice.  Can anyone explain what I am doing wrong?  The formula is: numberleft * massleft = masstotalleft This is my html                     <fieldset class="repeating_othergear">                         <div class='sheet-2colrow'>                             <div class='sheet-col'>                                 <table class="sheet-skill" style="width:100%">                                     <tr>                                         <th>Gear</th>                                         <th><input type="text" class="sheet-input" name="attr_gear_name-left" /></th>                                         <th>Amount</th>                                         <th><input type="number" class="sheet-input" name="attr_numberleft" value="0" /></th>                                         <th>Mass ea.</th>                                         <th><input type="number" class="sheet-input" name="attr_massleft" value="0" /></th>                                     </tr>                                     <tr>                                         <td><input type="number" class="sheet-input" name="attr_masstotalleft" value="0" /></tr></td>                                     </tr>                                     <tr>                                         <td colspan="6"><textarea class="sheet-input" name="attr_gearnotes-left"></textarea></td>                                     </tr>                                 </table>                             </div>                             <div class='sheet-col'>                             <table class="sheet-skill" style="width:100%">                                     <tr>                                         <th>Gear</th>                                         <th><input type="text" class="sheet-input" name="attr_gear_name-right" /></th>                                         <th>Amount</th>                                         <th><input type="number" class="sheet-input" name="attr_numberright" value="0" /></th>                                         <th>Mass ea.</th>                                         <th><input type="number" class="sheet-input" name="attr_massright" value="0"/></th>                                     </tr>                                     <tr>                                         <td><input type="number" class="sheet-input" name="attr_masstotalright" value="0" /></tr></td>                                     </tr>                                     <tr>                                         <td colspan="4"><textarea class="sheet-input" name="attr_gearnotes-right"></textarea></td>                                     </tr>                                 </table>                             </div>                         </div>                     </fieldset> And this is what I am working with in the sheet worker:      on("change:repeating_othergear:massleft change:repeating_othergear:numberleft sheet:opened", function() {    getAttrs([       "repeating_othergear_massleft", "repeating_othergear_numberleft"     ], function(values) {             repeating_othergear_masstotalleft: values.repeating_othergear_massleft * values.repeating_othergear_numberleft             });         });     }); Thanks for your time.
1485782682
Kryx
Pro
Sheet Author
API Scripter
You need to use  getSectionIDs for repeating sections. You'll probably also need to convert those values to intergers (or floats) using parseInt(VALUE, 10) or parseFloat(VALUE) for them to multiply.
This worked when I was just adding or subtracting the values.  What the difference now?
1485813609
Kryx
Pro
Sheet Author
API Scripter
I suspect it didn't work as there is nothing named "repeating_othergear_masstotal_left". Everything with repeating has an ID and you need to reference it by that ID.
1485816707
Lithl
Pro
Sheet Author
API Scripter
You only seed getSectionIDs if you're trying to operate on multiple rows. If your calculation is only affecting a single row, it's not necessary. However, Kryx's other point is well-taken: you should absolutely parseInt or parseFloat any values you expect to be numbers. On the backend, attributes might be stored as numbers or strings, and trying to do math on strings will sometimes behave how you want, while other times it won't. Fortunately, parseInt or parseFloat are (essentially) no-op when given a number, so it doesn't matter what the value was originally, you're guaranteed to have a number after parsing.
...okay.  How do I do that?
1485818547
Kryx
Pro
Sheet Author
API Scripter
Kryx said: You'll probably also need to convert those values to intergers (or floats) using parseInt(VALUE, 10) or parseFloat(VALUE) for them to multiply. repeating_othergear_masstotalleft: parseFloat(values.repeating_othergear_massleft) * parseFloat(values.repeating_othergear_numberleft)
Thank you Kryx and Brian.  That fixed it.  That was a big item off my list