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

Repeating sections question + bonus question

1543213188

Edited 1543278884
Hi hi, For the past year I've been trying to make my own character sheet for a home-brew system. On the home stretch now but as I'm ironing out the kinks I'm finding new problems. This time its as follows, is there a way to reference a repeating section and sum them up in a separate area of the character sheet? <div class="sheet-table"> <fieldset class="repeating_item"> <span class="sheet-table-data-center" style="width:40%;"><input title="repeating_item_$X_item-name" type="text" name="attr_item-name"></span> <span class="sheet-table-data-center" style="width:5%;"><input title="repeating_item_$X_item-qty" step="0.1" type="number" name="attr_item-qty" value="0"></span> <span class="sheet-table-data-center" style="width:5%;"><input title="repeating_item_$X_item-bulk" step="0.1" type="number" name="attr_item-bulk" value="0"></span> <span class="sheet-table-data-center" style="width:5%;"><input title="repeating_item_$X_item-total" step="0.1" type="number" name="attr_ item-total" value="(@{item-bulk} * @{item-qty}) " disabled></span> <span class="sheet-table-data-center" style="width:50%;"><input title="repeating_item_$X_item-description" type="text" name="attr_item-description"></span> </fieldset> </div> In the example above I'm trying to sum up all the item's weights all together within the following: <span class="sheet-table-data-center"><input style="width:100%;" title="carried-total" type="number" step="0.1" name="attr_carried-total" value="@{item-total} " disabled></span> Usually I'd think this'd work but it just ends up in a blank box. Bonus Question answered by GiGs, Thank you! Bonus question, I have multiple rolls that look kinda like this: <span class="sheet-table-data-center"><button style="font-size:100%;" title="Archery-Check" type="roll" value="&{template:default} {{name=@{character_name}'s Archery Check}} {{Check=[[1d20cs=20cf=1 + @{Archery}]]}}" name="roll_Archery-Check"></button></span> but when you hover over the result with your cursor in chat it shows this: Rolling 1d20cs=20cf=1 + floor(0 / 10 + floor((25 + 0 + 0 + 0 + 0 + 0 + 0 + 0) / 10) /2 + floor((25 + 0 + 0 + 0 + 0 + 0 + 0 + 0) / 10) /2 + 0 + 0 + 0 + 0 + 0) = (4)+floor(0/10+floor((25+0+0+0+0+0+0+0)/10)/2+floor((25+0+0+0+0+0+0+0)/10)/2+0+0+0+0+0) Is there any way to clean this up or am I stuck with it cause of sloppy code? Bonus bonus question! (Cause I found it after I posted this and I don't wanna clog up the forums with another post) PT.1, Is there a way to make a critical damage roll only show up if you actually roll a crit? Currently no matter what I roll the crit damage always shows up and from what I've found roll20 doesn't allow if/then statements. This is what the weapons section currently looks like: <div class="sheet-pc-weapons"> <div class="sheet-table"> <span class="sheet-table-name">Weapons</span> <fieldset class="repeating_pc-weapon"> <div class="sheet-table"> <div class="sheet-table-row1"> <span class="sheet-table-data sheet-center" style="width:5%;"><button type="roll" name="roll_roll" title="%{repeating_pc-weapon_$X_roll}" value="@{macro-text}"></button></span> <span class="sheet-table-data sheet-center sheet-small-label" style="width:20%;"><input type="text" name="attr_pc-weapon-name" title="@{repeating_pc-weapon_$X_pc-weapon-name}" placeholder="Name" ><br>Name</span> <span class="sheet-table-data sheet-center sheet-small-label" style="width:10%;"> <select title="@{repeating_pc-weapon_$X_pc-skill-type}" name="attr_pc-skill-type"> <option value="0" >None</option> <option value="1d20 + @{One-handed}" >One-Handed</option> <option value="1d20 + @{Two-handed}" >Two-Handed</option> <option value="1d20 + @{Archery}" >Archery</option> <option value="1d20 + @{Pugilism}" >Pugilism</option> </select> <br>Attack Type </span> <span class="sheet-table-data sheet-center sheet-small-label" style="width:15%;"><input type="number" name="attr_pc-damage" title="@{repeating_pc-weapon_$X_pc-damage}" placeholder="Damage" value="0" ><br>Damage</span> <span class="sheet-table-data sheet-center sheet-small-label" style="width:15%;"><input type="number" name="attr_pc-damage-mod" title="@{repeating_pc-weapon_$X_pc-damage-mod}" placeholder="Damage Modifiers" value="0" ><br>Damage Mods</span> </div> </div> <div class="sheet-table"> <div class="sheet-table-row1"> <span class="sheet-table-data sheet-center sheet-small-label" style="width:15%;"><input type="text" name="attr_pc-weapon-critical" title="@{repeating_pc-weapon_$X_pc-weapon-critical}" placeholder="none"><br>Crit Multiplier</span> <span class="sheet-table-data sheet-center sheet-small-label" style="width:5%;"><input type="number" name="attr_pc-weapon-range" title="@{repeating_pc-weapon_$X_pc-weapon-range}" min="0" value="0" ><br>Range</span> <span class="sheet-table-data sheet-center sheet-small-label" style="width:15%;"><input type="text" name="attr_pc-weapon-type" title="@{repeating_pc-weapon_$X_pc-weapon-type}" placeholder="Damage Type" ><br>Damage Type</span> <span class="sheet-table-data sheet-center sheet-small-label" style="width:5%;"><input type="number" name="attr_pc-weapon-ammo" title="@{repeating_pc-weapon_$X_pc-weapon-ammo}" value="0" ><br>Ammo</span> <span class="sheet-table-data sheet-center sheet-small-label" style="width:48%;"><input type="text" name="attr_pc-weapon-notes" title="@{repeating_pc-weapon_$X_pc-weapon-notes}" placeholder="Attack Notes" ><br>Notes</span>         </div> </div> PT.2, for that matter, is there any way I can just make the dropdown use the roll from One-handed, Two-handed, Archery or Pugilism? The rolls look like this: <span class="sheet-table-row-name"><button class="sheet-text-button" title="DEX-Check" type="roll" name="roll_DEX-Check" value="&{template:default} {{name=@{character_name}'s Dexterity check}} {{check=[[@{DEX-mod} + 1d20cs=20cf=1]]}}"></button></span> If I try to use @{One-handed-Check} in the drop down it tells me there's "no One-handed-Check attribute". I'm probably overlooking something super simple but I never see it before asking for help, thank you in advance to anyone willing to help!
Here's what the first part looks like in sheet.
1543218457
GiGs
Pro
Sheet Author
API Scripter
For the first question, you'll need to use a sheet worker to sum up the inventory. I'll post up some code later. Feel free to ping me to remind me if it takes more than a day. Does the @{Archery} stat include a lot of calculation with the floor() function used? I cant see where all the extra calculations in that example are coming from. If that's were they are coming from, wrap another [[ ]] around Archery, and it might suppress them, like so: {{Check=[[1d20cs=20cf=1 + [[@{Archery}]] ]]}} Also, I've never seen the = sign with cf and cs. I guess it sill works? I'd have written it {{Check=[[1d20cs>20cf<1 + [[@{Archery}]] ]]}} or {{Check=[[1d20cs20cf1 + [[@{Archery}]] ]]}} But if the = version works, that's perfectly fine! To be honest, when they are 20 and 1, i dont think you actually need to list them unless you are using the critical effects in the rolltemplate.
The brackets didn't work for it :/ Though I did just delete the cs cf thing and its still fine like you said. This is what the whole archery thing looks like: <div class="sheet-table-row"> <span class="sheet-table-data-center"><button style="font-size:100%;" title="Archery-Check" type="roll" value="&{template:default} {{name=@{character_name}'s Archery Check}} {{Check=[[1d20 + [[@{Archery}]] ]]}}" name="roll_Archery-Check"></button></span> <span class="sheet-table-data-center"><button style="font-size:100%;" title="Archery-Check" type="roll" value="/w GM &{template:default} {{name=@{character_name}'s Archery Check}} {{Check=[[@{Archery} + 1d20cs=20cf=1]]}}" name="roll_Archery-Check"></button></span> <span class="sheet-table-data-center">Archery</span> <span class="sheet-table-data-center"><input title="Archery" type="number" name="attr_Archery" value="floor(@{Archery-ranks} / 10 + @{DEX-mod} /2 + @{END-mod} /2 + @{Archery-trained1} + @{Archery-trained2} + @{Archery-trained3} + @{Archery-trained4} + @{Archery-misc})" disabled></span> <span class="sheet-table-data-center"><input title="Archery-ranks" type="number" name="attr_Archery-ranks" value="0"></span> <span class="sheet-table-data-center">END/DEX</span> <span class="sheet-table-data-center"><input title="Archery-trained" type="checkbox" name="attr_Archery-trained1" value="2" /></span> <span class="sheet-table-data-center"><input title="Archery-trained" type="checkbox" name="attr_Archery-trained2" value="2" /></span> <span class="sheet-table-data-center"><input title="Archery-trained" type="checkbox" name="attr_Archery-trained3" value="2" /></span> <span class="sheet-table-data-center"><input title="Archery-trained" type="checkbox" name="attr_Archery-trained4" value="4" /></span> <span class="sheet-table-data-center"><input title="Archery-misc" type="number" name="attr_Archery-misc" value="0"></span> </div> And for where it mentions the DEX or END mod it references this: <div class="sheet-table-row"> <span class="sheet-table-data-center">DEX</span> <span class="sheet-table-row-name"><button class="sheet-text-button" title="DEX-Check" type="roll" name="roll_DEX-Check" value="&{template:default} {{name=@{character_name}'s Dexterity check}} {{check=[[@{DEX-mod} + 1d20cs=20cf=1]]}}"></button></span> <span class="sheet-table-row-name"><button class="sheet-text-button" title="DEX-Check" type="roll" name="roll_DEX-Check" value="/w GM &{template:default} {{name=@{character_name}'s Dexterity check}} {{check=[[@{DEX-mod} + 1d20cs=20cf=1]]}}"></button></span> <span class="sheet-table-data-center"><input title="DEX-tag" type="checkbox" name="attr_DEX-tag1" value="5" /></span> <span class="sheet-table-data-center"><input title="DEX-tag" type="checkbox" name="attr_DEX-tag2" value="5" /></span> <span class="sheet-table-data-center"><input title="DEX-tag" type="checkbox" name="attr_DEX-tag3" value="5" /></span> <span class="sheet-table-data-center"><input title="DEX-tag" type="checkbox" name="attr_DEX-tag4" value="5" /></span> <span class="sheet-table-data-center"><input title="DEX-race" type="checkbox" name="attr_DEX-race" value="5" /></span> <span class="sheet-table-data-center"><input title="DEX-mod" type="number" name="attr_DEX-mod" value="floor(@{DEX} / 10)" disabled></span> <span class="sheet-table-data-center"><input title="DEX" type="number" name="attr_DEX" value="(25 + @{DEX-race} + @{DEX-tag1} + @{DEX-tag2} + @{DEX-tag3} + @{DEX-tag4} + @{DEX-point_buy} + @{DEX-abil_incr})" disabled></span> <span class="sheet-table-data-center"><input title="DEX-point_buy" type="number" name="attr_DEX-point_buy" value="0"></span> <span class="sheet-table-data-center"><input title="DEX-abil_incr" type="number" name="attr_DEX-abil_incr" value="0"></span> </div>
NEVERMIND! I put the brackets around the @{Archery-ranks} / 10 + @{DEX-mod} /2 + @{END-mod} /2 + @{Archery-trained1} + @{Archery-trained2} + @{Archery-trained3} + @{Archery-trained4} + @{Archery-misc} part and it cleaned up! Thanks a lot!
1543240084
GiGs
Pro
Sheet Author
API Scripter
Yay :) I added a page in the roll20 wiki for summing items in a repeating section, like your inventory, here:&nbsp; <a href="https://wiki.roll20.net/RepeatingSum" rel="nofollow">https://wiki.roll20.net/RepeatingSum</a> Here's how to use it. First change your carried-total attribute to this: &lt;span class="sheet-table-data-center"&gt;&lt;input style="width:100%;" title="carried-total" type="number" name="attr_carried-total" value=0 readonly&gt;&lt;/span&gt; Now add the following sheet workers to your charactersheet. Note: if you don't already have a script section in your character sheet, first add this to the bottom of your html file, and put the sheet workers inside it: &lt;script type="text/worker"&gt; // all your sheet workers go here &lt;/script&gt; On to the sheet workers: let repeatingSum = function (destination, section, quantity, units, multiplytotal){ let multiplier = true; if (units === undefined || units === false || units === 'false') multiplier = false; if (multiplytotal === undefined) multiplytotal = 1; getSectionIDs(`repeating_${section}`, (idArray) =&gt; { const quantityFields = idArray.map(id =&gt; `repeating_${section}_${id}_${quantity}`); const unitFields = multiplier&nbsp;? idArray.map(id =&gt; `repeating_${section}_${id}_${units}`)&nbsp;: []; getAttrs(quantityFields.concat(unitFields), (v) =&gt; { console.log("===== values of v: "+ JSON.stringify(v) +" ====="); let sumTotal = 0; const rowValues = quantityFields.map(attr =&gt; parseInt(v[attr], 10) || 0); if(multiplier) { const rowMultiples = unitFields.map(attr =&gt; parseInt(v[attr], 10) || 0); sumTotal = _.zip(rowValues, rowMultiples).map(([a, b]) =&gt; a*b).reduce((m, x) =&gt; m + x, 0); } else { sumTotal = rowValues.reduce((m, x) =&gt; m + x, 0); } setAttrs({[destination]: sumTotal * multiplytotal}); }); }); } on('change:repeating_pc-weapon remove:repeating_pc-weapon', function() { repeatingSum(" carried-total ","pc-weapon","item-total"); }); One bit of advice: remove all the hyphens in your attribute names with underscores, or remove them completely. So item-total would become item_total or itemtotal . (If you do, you'll need to correct the scripts above too.) Once you starting using sheet workers, hyphens in attribute names can lead to errors if you aren't careful, and sometimes makes the coding syntax a little more complicated than it needs to be. The above function should still work okay, but it's just something to be aware of.
1543240282
GiGs
Pro
Sheet Author
API Scripter
Regarding your bonus bonus question, you should have added that in another post (even if in this thread). people dont get notified of edits to posts, so i didnt know you'd added another question till I had to check your fieldnames for my last post. There is a way to show critical damage only if you roll a critical, but only if you create a rolltemplate for your sheet and use the Helper functions, described on this page:&nbsp;<a href="https://wiki.roll20.net/Roll_Templates" rel="nofollow">https://wiki.roll20.net/Roll_Templates</a>
1543249667
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
For pt2 of your bonus bonus question, do you in fact have those attributes created somewhere on the sheet? And where are you wanting to call the query? I don't see a button in that repeating section code. And what drop-down are you wanting to use this in? I had thought you meant the select, but now I'm not so sure. And, if you don't mind some code critique: Why are all your inputs wrapped in spans? And why do some of those spans also contain &lt;br&gt; someWord.&nbsp;
1543281388

Edited 1543281579
To GiGs, Oh man that is all kinda of complicated, thank you for your help and the reading material. I'm not sure if I have a script section, I assume I don't because I don't know. I'll get back to you once I've put it all in there, and thanks for the tips on the bonus bonus. To Scott C. No, I'm just using @{Archery-Check} which I assume I cant do because its a roll button that I'm trying to reference name="roll_Archery-Check" rather than a field with a number in it like name="attr_Archery-Check" I don't understand what you mean by where I want to call the query, the button is the first line span class="sheet-table-data sheet-center" style="width:5%;"&gt;&lt;button type="roll" name="roll_roll" title="%{repeating_pc-weapon_$X_roll}" value="@{macro-text}"&gt;&lt;/button&gt;&lt;/span&gt; and I'd like to be able to use &lt;select title="@{repeating_pc-weapon_$X_pc-skill-type}" name="attr_pc-skill-type"&gt; &lt;option value="0" &gt;None&lt;/option&gt; &lt;option value="1d20 + @{One-handed}" &gt;One-Handed&lt;/option&gt; &lt;option value="1d20 + @{Two-handed}" &gt;Two-Handed&lt;/option&gt; &lt;option value="1d20 + @{Archery}" &gt;Archery&lt;/option&gt; &lt;option value="1d20 + @{Pugilism}" &gt;Pugilism&lt;/option&gt; &lt;/select&gt; this drop down ^ to make the button change between rolling using the Archery, One-handed, Two-handed or Pugilism buttons such as the one below &lt;span class="sheet-table-data-center"&gt;&lt;button style="font-size:100%;" title="Archery-Check" type="roll" value="&amp;{template:default} {{name=@{character_name}'s Archery Check}} {{Check=[[1d20 + [[@{Archery}]] ]]}}" name="roll_Archery-Check"&gt;&lt;/button&gt;&lt;/span&gt; And I don't mind the critique at all, I'm still really new to this and basically everything I know is either from the wiki or from ripping apart other character sheets and learning what the HTML sections do. For example my sheet started as a Starfinder character sheet and I've just been slowly taking pieces out of it, figuring out how it works, re-writing it and putting it back in, usually in a different place. So to answer the inputs wrapped in spans question, I have no idea, I wasn't aware it could be done differently. And the &lt;br&gt; someWord parts I just kept inside because they helped make labels on the underside of certain fields like in the picture I posted above, the Current, unencumbered, encumbered and overburdened labels came from that, though I just noticed everything is shifted to the right for some reason.
1543308307
GiGs
Pro
Sheet Author
API Scripter
Sorrin P. said: To GiGs, Oh man that is all kinda of complicated, thank you for your help and the reading material. I'm not sure if I have a script section, I assume I don't because I don't know. I'll get back to you once I've put it all in there, and thanks for the tips on the bonus bonus. Do a search for "text/worker" in your html file. If you find that, that's your script section. If not, copy this into your sheet &lt;script type="text/worker"&gt; // all your sheet workers go here &lt;/script&gt; And any sheet workers like the one I posted above get put between those two script tags.
Alright so I've put it in and removed all the hyphens but it doesn't seem to be working, I'm not sure what I'm missing. Here is the inventory and encumbrance parts with hyphen's changed: &lt;div class="sheet-pc-inventory"&gt; &lt;div class="sheet-table"&gt; &lt;span class="sheet-table-name"&gt;Inventory&lt;/span&gt; &lt;div class="sheet-table-row"&gt; &lt;span class="sheet-table-header" style="width:40%;"&gt;Name&lt;/span&gt; &lt;span class="sheet-table-header" style="width:5%;"&gt;Quantity&lt;/span&gt; &lt;span class="sheet-table-header" style="width:5%;"&gt;Weight&lt;/span&gt; &lt;span class="sheet-table-header" style="width:5%;"&gt;Weight&lt;/span&gt; &lt;span class="sheet-table-header" style="width:50%;"&gt;Description&lt;/span&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="sheet-table"&gt; &lt;fieldset class="repeating_item"&gt; &lt;span class="sheet-table-data-center" style="width:40%;"&gt;&lt;input title="repeating_item_$X_item_name" type="text" name="attr_item_name"&gt;&lt;/span&gt; &lt;span class="sheet-table-data-center" style="width:5%;"&gt;&lt;input title="repeating_item_$X_item_qty" step="0.1" type="number" name="attr_item_qty" value="0"&gt;&lt;/span&gt; &lt;span class="sheet-table-data-center" style="width:5%;"&gt;&lt;input title="repeating_item_$X_item_bulk" step="0.1" type="number" name="attr_item_bulk" value="0"&gt;&lt;/span&gt; &lt;span class="sheet-table-data-center" style="width:5%;"&gt;&lt;input title="repeating_item_$X_item_total" step="0.1" type="number" name="attr_item_total" value="(@{item_bulk} * @{item_qty})" disabled&gt;&lt;/span&gt; &lt;span class="sheet-table-data-center" style="width:50%;"&gt;&lt;input title="repeating_item_$X_item_description" type="text" name="attr_item_description"&gt;&lt;/span&gt; &lt;/fieldset&gt; &lt;/div&gt; &lt;/div&gt; &lt;br&gt; &lt;b&gt;Show Encumbrance?&lt;/b&gt; &lt;input type="checkbox" class="sheet-pc-encumbrance-show" title="encumbrance-show" name="attr_encumbrance-show" value="1"/&gt; &lt;div class="sheet-table sheet-pc-encumbrance"&gt; &lt;div class="sheet-table-row"&gt; &lt;div class="sheet-table-data-center" style="vertical-align:top;"&gt; &lt;div class="sheet-table"&gt; &lt;div class="sheet-table-row"&gt; &lt;span class="sheet-table-name"&gt;Current Weight&lt;/span&gt; &lt;div class="sheet-table-row"&gt; &lt;span class="sheet-table-header"&gt;Weight&lt;/span&gt; &lt;/div&gt; &lt;div class="sheet-table-row"&gt; &lt;span class="sheet-table-data-center"&gt;&lt;input style="width:100%;" title="carried_total" type="number" name="attr_carried_total" value=0 readonly&gt;&lt;/span&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; And here's the script part with the hyphen's changed: &lt;script type="text/worker"&gt; let repeatingSum = function (destination, section, quantity, units, multiplytotal){ &nbsp;&nbsp;&nbsp; let multiplier = true; &nbsp;&nbsp;&nbsp; if (units === undefined || units === false || units === 'false') multiplier = false; &nbsp;&nbsp;&nbsp; if (multiplytotal === undefined) multiplytotal = 1; &nbsp;&nbsp;&nbsp; getSectionIDs(`repeating_${section}`, (idArray) =&gt; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const quantityFields = idArray.map(id =&gt; `repeating_${section}_${id}_${quantity}`); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const unitFields = multiplier ? idArray.map(id =&gt; `repeating_${section}_${id}_${units}`) : []; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getAttrs(quantityFields.concat(unitFields), (v) =&gt; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; console.log("===== values of v: "+ JSON.stringify(v) +" ====="); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; let sumTotal = 0; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const rowValues = quantityFields.map(attr =&gt; parseInt(v[attr], 10) || 0); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(multiplier) { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const rowMultiples = unitFields.map(attr =&gt; parseInt(v[attr], 10) || 0); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sumTotal = _.zip(rowValues, rowMultiples).map(([a, b]) =&gt; a*b).reduce((m, x) =&gt; m + x, 0); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sumTotal = rowValues.reduce((m, x) =&gt; m + x, 0); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setAttrs({[destination]: sumTotal * multiplytotal});&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }); &nbsp;&nbsp;&nbsp; }); } on('change:repeating_pc_weapon remove:repeating_pc_weapon', function() { &nbsp;&nbsp;&nbsp; repeatingSum("carried_total","pc_weapon","item_total"); }); &lt;/script&gt; Was I only supposed to have that last part reference "carried_total", "pc_weapon" and "item_total" or was I supposed to go back through the sheetworkers and insert the referenced area into the script in places like where it says "destination", "section" or "quantity" ? Sorry for being a pain :/
1543393920

Edited 1543394145
GiGs
Pro
Sheet Author
API Scripter
Edit: &nbsp;see next post for a simpler solution! I just noticed your item_total field is an autocalc field. Sheet workers dont work with those.&nbsp; When working with sheet workers, the dependent attributes should all be calculated with sheet workers too. Here's how to do that: Change your html for that line to &lt;input title="repeating_item_$X_item_total" type="number" name="attr_item_total" value="0" readonly&gt; (aside: what is that title tag doing there? does it do anything?) And then add this to your script section with the other two sheet workers: on("change:repeating_item:item_bulk change:repeating_item:item_qty", function() { getAttrs(['repeating_item_item_bulk','repeating_item_item_qty'], function(values) { let bulk = parseInt(values.repeating_item_item_bulk,10)||0; let qty = parseInt(values.repeating_item_item_qty,10)||0; setAttrs({ repeating_item_item_total: bulk*qty }); }); }); Hopefully that gets things working for you.
1543394473

Edited 1543395847
GiGs
Pro
Sheet Author
API Scripter
Another way to fix this occurred to me a few minutes after posting. You can bypass the autocalc field automatically with one simple change.&nbsp; Change this sheet worker on('change:repeating_pc_weapon remove:repeating_pc_weapon', function() { &nbsp;&nbsp;&nbsp; repeatingSum("carried_total","pc_weapon","item_total"); }); To this on('change:repeating_pc_weapon remove:repeating_pc_weapon', function() { &nbsp;&nbsp;&nbsp; repeatingSum("carried_total","pc_weapon","item_bulk", "item_qty"); }); The repeatingSum function is designed to multiply two fields together like this if you add the 2nd field as above. If you do this, you can ignore the changes suggested in the previous post. To answer a question you asked: Was I only supposed to have that last part reference "carried_total", "pc_weapon" and "item_total" or was I supposed to go back through the sheetworkers and insert the referenced area into the script in places like where it says "destination", "section" or "quantity" ? The repeatingSum fucntion is designed as a drop-in function - you don't change it at all. When you run a function like&nbsp; &nbsp;&nbsp;&nbsp; repeatingSum("carried_total","pc_weapon","item_bulk", "item_qty"); it automatically assigns 'carried_total' to 'destination', 'pc_weapon' to 'section', and so on, and you don't need to do anything.
1543398523

Edited 1543398615
I feel like I'm doing something wrong, I tried both methods and they don't work, also for some reason when I replace the item_total line everything gets smashed to the right of the page. No worries though if I can't get this to work I thought of a slightly more pen and paper-y way to solve the problem. I'm just trying to make the sheet as smooth as I can get it for the players, I have a habit of digging holes too deep for myself. It's my first time DMing, let alone making my own system, so I'm kinda laughing about having gone this far for it XD. I had a question about the sheet worker on('change:repeating_pc_weapon remove:repeating_pc_weapon', function() { &nbsp;&nbsp;&nbsp; repeatingSum("carried_total","pc_weapon","item_bulk", "item_qty"); }); why does it reference pc_weapon? Is it trying to rule out other repeating sections? Cause my sheet as like seven of them. Would it be easier to diagnose if I just put up the whole sheet? Also, thank you very much for your continued help and patience.
1543401505
GiGs
Pro
Sheet Author
API Scripter
Sorrin P. said: I had a question about the sheet worker on('change:repeating_pc_weapon remove:repeating_pc_weapon', function() { &nbsp;&nbsp;&nbsp; repeatingSum("carried_total","pc_weapon","item_bulk", "item_qty"); }); why does it reference pc_weapon? Is it trying to rule out other repeating sections? Cause my sheet as like seven of them. Would it be easier to diagnose if I just put up the whole sheet? Also, thank you very much for your continued help and patience. Doh - well spotted! Your first html example at the top of this thread was a pc_weapon section, I didnt norice I was still using that. It should be the name of the enconmbrance section,&nbsp;repeating_item. Try this: on('change:repeating_pc_weapon remove:repeating_pc_weapon', function() { &nbsp;&nbsp;&nbsp; repeatingSum("carried_total","repeating_item","item_bulk", "item_qty"); });
It still doesn't work, I think for now I'll just nix this and put it back in once I have a better understanding of it. My first session is this weekend and I've still got some storyline elements to work out. Thank you for your help, and for setting up the wiki page for it. I'll take some time to study up on it more so that way I can understand how and why it works before I implement it. Again, thank you, you've been a tremendous help!
1543478401

Edited 1543483586
GiGs
Pro
Sheet Author
API Scripter
If you post your character sheet (html and css) to pastebin or gist or somewhere i can grab the whole files, I'll figure out why it isnt working and you can work on your session.
Sorry for the gap in response, was busy with family stuff. Anywho, that would be really awesome! Here's the html <a href="https://pastebin.com/gqF50LcE" rel="nofollow">https://pastebin.com/gqF50LcE</a> and here's the css <a href="https://pastebin.com/Mabm8eWg" rel="nofollow">https://pastebin.com/Mabm8eWg</a> I delayed the first game to next Sunday because I've got to help the family put up Christmas decorations so luckily I've got another week to plan.
1543752590
GiGs
Pro
Sheet Author
API Scripter
This html doesnt have a script section. Where did you add the sheet worker I posted earlier?
1543753149
GiGs
Pro
Sheet Author
API Scripter
Here's the working version: <a href="https://pastebin.com/j8142Nnm" rel="nofollow">https://pastebin.com/j8142Nnm</a> I just added this to the very end of the html file, no other changes needed: &lt;script type="text/worker"&gt; let repeatingSum = function (destination, section, quantity, units, multiplytotal){ &nbsp; &nbsp; let multiplier = true; &nbsp; &nbsp; if (units === undefined || units === false || units === 'false') multiplier = false; &nbsp; &nbsp; if (multiplytotal === undefined) multiplytotal = 1; &nbsp; &nbsp; getSectionIDs(`repeating_${section}`, (idArray) =&gt; { &nbsp; &nbsp; &nbsp; &nbsp; const quantityFields = idArray.map(id =&gt; `repeating_${section}_${id}_${quantity}`); &nbsp; &nbsp; &nbsp; &nbsp; const unitFields = multiplier ? idArray.map(id =&gt; `repeating_${section}_${id}_${units}`) : []; &nbsp; &nbsp; &nbsp; &nbsp; getAttrs(quantityFields.concat(unitFields), (v) =&gt; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log("===== values of v: "+ JSON.stringify(v) +" ====="); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let sumTotal = 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const rowValues = quantityFields.map(attr =&gt; parseInt(v[attr], 10) || 0); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(multiplier) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const rowMultiples = unitFields.map(attr =&gt; parseInt(v[attr], 10) || 0); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sumTotal = _.zip(rowValues, rowMultiples).map(([a, b]) =&gt; a*b).reduce((m, x) =&gt; m + x, 0); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sumTotal = rowValues.reduce((m, x) =&gt; m + x, 0); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setAttrs({[destination]: sumTotal * multiplytotal});&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; }); } on('change:repeating_item remove:repeating_item', function() { &nbsp; &nbsp; repeatingSum("carried_total","item","item_bulk","item_qty"); }); &lt;/script&gt;
Oh sorry, yeah I took it out while I was editing, just in case. And WOOO thanks so much, it works! Though I do have one question, is there a way to allow it to display decimals? Many of the items in my game weigh .1 to .5 and whenever I input a decimal into the quantity section the carried_total number either becomes a 0 or doesn't reflect the change, even if the individual totals are all whole numbers.
1543795085
GiGs
Pro
Sheet Author
API Scripter
ah, great question, that's on oversight in my code, i used parseInt where i should have used parseFloat. Replace the sheet worker code at the end with this: &lt;script type="text/worker"&gt; let repeatingSum = function (destination, section, quantity, units, multiplytotal){ &nbsp; &nbsp; let multiplier = true; &nbsp; &nbsp; if (units === undefined || units === false || units === 'false') multiplier = false; &nbsp; &nbsp; if (multiplytotal === undefined) multiplytotal = 1; &nbsp; &nbsp; getSectionIDs(`repeating_${section}`, (idArray) =&gt; { &nbsp; &nbsp; &nbsp; &nbsp; const quantityFields = idArray.map(id =&gt; `repeating_${section}_${id}_${quantity}`); &nbsp; &nbsp; &nbsp; &nbsp; const unitFields = multiplier ? idArray.map(id =&gt; `repeating_${section}_${id}_${units}`) : []; &nbsp; &nbsp; &nbsp; &nbsp; getAttrs(quantityFields.concat(unitFields), (v) =&gt; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log("===== values of v: "+ JSON.stringify(v) +" ====="); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let sumTotal = 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const rowValues = quantityFields.map(attr =&gt; parseFloat(v[attr], 10) || 0); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(multiplier) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const rowMultiples = unitFields.map(attr =&gt; parseFloat(v[attr], 10) || 0); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sumTotal = _.zip(rowValues, rowMultiples).map(([a, b]) =&gt; a*b).reduce((m, x) =&gt; m + x, 0); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sumTotal = rowValues.reduce((m, x) =&gt; m + x, 0); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setAttrs({[destination]: sumTotal * multiplytotal});&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; }); } on('change:repeating_item remove:repeating_item', function() { &nbsp; &nbsp; repeatingSum("carried_total","item","item_bulk","item_qty"); }); &lt;/script&gt;
Awesome! It works perfect, thank you so much! I only have one last question, though its not really code related. Since you got to see my sheet, as a sheet author do you have any suggestions / critiques on the sheet itself, such as layout, content and even the html behind it? Always looking to improve!
1543852008
GiGs
Pro
Sheet Author
API Scripter
I'm no html/css expert, but the biggest thing I noticed was mentioned by Scott earlier: it looks like you are using span elements in a very unusual way. You also seem to be using placeholder and title elements in place of visible labels. Another issue is you use style for some elements a lot (I did this a lot on my first sheet too), when ideally they should be moved off in the css sheet as classes. For instance: &lt;span class="sheet-table-data-center" style="width:20%;"&gt;&lt;input title="Age" type="text" name="attr_age" placeholder="Age"/&gt;&lt;/span&gt; I would do this as: &lt;label class="whatever"&gt;Age: &lt;/label&gt;&lt;input type="number" class="table-data-center w20"&nbsp;name="attr_age"&nbsp;/&gt; And add a css element for the width: (obviously the width would be less than 20% if you are adding a label element). .sheet-w20 { width:20%; } You might also need to add an inline-block style to the classes for label and input above, to make sure they stay on the same line.&nbsp; But html/css has a huge learning curve, and is extremely tedious and fiddly to get right at first. You might find it worthwhile looking at grid elements which are helpful to get things lined up nicely.