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

[help] Not understanding sheetworkers still.

1501886936
Pat S.
Forum Champion
Sheet Author
I'm revisiting a sore spot for my sheet. I'm still not understanding how to get my inventory weight to total up and display. I have a repeating field section and need all the repeating fields of “ attr_itemwornenc” to total up then display in another section with the attribute named “attr_inventory_weight”. <!-- Inventory Page 1--> <div> <input type="text" name="attr_tabinvtitle1" value="What is being worn or carried on person " disabled="disabled"> <div> <div>Name</div> <div>Qty</div> <div>Uses</div> <div>Weight</div> <div>Notes</div> </div> <fieldset> <div> <div><input type="text" name="attr_itemname"></div> <div><input type="number" name="attr_itemquantity"></div> <div><input type="number" name="attr_itemuses"></div> <div><input type="number" name="attr_itemwornenc"></div> <div><input type="text" name="attr_itemdesc"></div> </div> </fieldset> </div> Any suggestions or help would be greatly appreciated.
I would suggest using TAS for this. It would look like: //Mount Equipment Carried Section on('change:repeating_gear-stored', function(){          TAS.repeating('gear-stored')     .fields('gear-stored-weight','stored-qty','mountgearweight')     .reduce(function(m,r){         m['gear-stored-weight']+=(r.F['gear-stored-weight']*r.I['stored-qty']);         r.mountgearweight=(r.F['gear-stored-weight']*r.I['stored-qty']);         return m;              },{['gear-stored-weight']:0,['stored-qty']:0,['mountgearweight']:0, desc: []},function(m,r,a){         a.mountgearweight=m['gear-stored-weight'];     })     .execute(); }) In this case, there is a hidden field named attr_mountgearweight where it  calculates this information so it can be called or displayed elsewhere. In this box, it is executing the weight, multiplied by the quantity and storing that result. This occurs for every item line in the repeating section named gear-stored. Hope this helps :)
Yes, TheAaronSheet (TAS) makes this (and much more) very easy. Recommend it highly.
1501899404
Pat S.
Forum Champion
Sheet Author
I tried it once before and gave up in total confusion. Now after months of not working on my sheet, I'm back working on it.
1501941884
Pat S.
Forum Champion
Sheet Author
I'm screwing up something somewhere. I have the following: <script type="text/worker"> (TAS script) <!--inventory weight calculation--> // Equipment Carried Section on('change:repeating_inventtab1', function(){ TAS.repeating('inventtab1') .fields('attr_itemwornenc', 'attr_itemquantity') .reduce(function(m,r){ m['attr_itemwornenc']+=(r.F['itemwornenc']*r.I['itemquantity']); return m; },{['itemwornenc']:0,['itemquantity']:0, desc: []}, function (m,r,a){ a.inventory_weight=m['itemwornenc']; }) .execute(); }) </script> The display attr is called "inventory_weight" The fieldset used is called "repeating_inventtab1" The two repeating fields are called "attr_itemquantity" and "attr_itemwornenc". So where or what have I missed or screwed up? I'm not a coder and this is a foreign language to me.
1501949125

Edited 1501949535
I think you left out a line for the "destination" attributes. Also, you don't need to use the attr_ prefix within the TAS function here. See if you can duplicate the structure from this code from Diana's 3.5 D&D sheet: <script type="text/worker"> // //INSERT TAS HERE // on('change:repeating_equipment', function(){     TAS.repeating('equipment')         .attrs('totalequipmentweight','totalequipmentcost','summary')           .fields('equipmentname','equipmentquantity','equipmentweight','equipmenttotalweight','equipmentcost','equipmenttotalcost')         .reduce(function(m,r){             m.equipmentweight+=(r.F.equipmentweight*r.I.equipmentquantity);             r.D[3].equipmenttotalweight=(r.F.equipmentweight*r.I.equipmentquantity);             m.equipmentcost+=(r.F.equipmentcost*r.I.equipmentquantity);             r.D[2].equipmenttotalcost=(r.F.equipmentcost*r.I.equipmentquantity);             m.desc.push(r.equipmentname+(r.I.equipmentquantity>1 ? ' (x'+r.S.equipmentquantity+')' : ''));             return m;         },{equipmentweight:0,equipmentcost:0, desc: []},function(m,r,a){             a.summary=m.desc.join(', ');             a.D[3].totalequipmentweight=m.equipmentweight;             a.D[2].totalequipmentcost=m.equipmentcost;         })         .execute(); }); </script> I bolded the line I think you're missing. Looking at the attrs you have, I am guessing yours would be just the one display attribute (EDIT) and the summary: .attrs('inventory_weight', 'summary')   Hope this helps. I don't understand a lot of what it is doing "under the hood," but I can copy and tweak (and break and tweak, and break and tweak, and finally shout "Eureka! It works!").
As a point of comparison, here is the modified code I am using in my sheet. I don't care about computing the cost of the gear, so you can see some differences there that may be useful to you. Also, I have added the bolded text to the conditions, which should keep things accurately computing when you delete a repeating row or change an individual item's weight within a row. on("change:repeating_gear remove:repeating_gear change:repeating_gear:gear_weight ", function(){     TAS.repeating('gear')         .attrs('gear_total_weight','summary')           .fields('gear_name','gear_quantity','gear_weight','gear_total_weight')         .reduce(function(m,r){             m.gear_weight+=(r.F.gear_weight*r.I.gear_quantity);             r.D[2].gear_total_weight=(r.F.gear_weight*r.I.gear_quantity);             m.desc.push(r.gear_name+(r.I.gear_quantity>1 ? ' (x'+r.S.gear_quantity+')' : ''));             return m;         },{gear_weight:0, desc: []},function(m,r,a){             a.summary=m.desc.join(', ');             a.D[2].gear_total_weight=m.gear_weight;         })         .execute(); });
1501954189

Edited 1501954207
Pat S.
Forum Champion
Sheet Author
I'm guessing that I'm to thick headed to understand how it needs to be scripted. I've been trying to get this to work: <!--inventory weight calculation--> // Equipment Carried Section on("change:repeating_inventtab1 remove:repeating_inventtab1 change:inventtab1:itemwornenc, function(){ TAS.repeating('inventtab1') .attrs ('inventory_weight', 'summary') .fields('itemwornenc', 'itemquantity') .reduce(function(m,r){ m.itemwornenc+=(r.F.itemwornenc*r.I.itemquantity); r.D.inventory_weight=(r.F.itemwornenc*r.I.itemquantity) return m; },{['itemwornenc']:0,['itemquantity']:0, desc: []}, function (m,r,a){ a.inventory_weight=m['itemwornenc']; }) .execute(); }) but it is still non-functioning. These is the code snippets that I'm trying to pull from and display to <div><input type="number" name=" attr_inventory_weight " title="Total of your equipment Worn and Carried" disabled="disabled"></div> <div><input type="number" name="attr_coin_weight" value="((@{CP} + @{SP} + @{GP})/10)" disabled="disabled"></div> <div><input type="number" name="attr_other_weight" value="0" min="0"></div> <div><input type="number" name="attr_total_weight" value="@{inventory_weight} + @{coin_weight} + @{other_weight}" disabled="disabled"></div> </div> <h4>Equipment </h4> <input type="radio" name="attr_inventorytab" value="1" title="Page 1" checked="checked" /> <span>On Person</span> <!-- Inventory Page 1--> <div> <input type="text" name="attr_tabinvtitle1" value="What is being worn or carried on person " disabled="disabled"> <div> <div>Name</div> <div>Qty</div> <div>Weight</div> <div>Notes</div> </div> <fieldset> <div> <div><input type="text" name="attr_itemname"></div> <div><input type="number" name="attr_itemquantity"></div> <div><input type="number" name="attr_itemwornenc"></div> <div><input type="text" name="attr_itemdesc"></div> </div> </fieldset> </div> Those three items are all that I need to work with. The itemquantity is how many and the itemwornenc is the weight. I just need the total of those two combined to be displayed outside the fieldset with the attribute inventory_weight. This is frustrating even with all the help I've gotten, I'm just not understanding it.
1501957024
Diana P
Pro
Sheet Author
In the "is it plugged in?" category.... you did put the code for TAS in your scripts section as well, right? on the 3.5 sheet the equipment weight calculation section actually starts: &lt;script type="text/worker"&gt; /* ---- BEGIN: TheAaronSheet.js ---- */ // Github:&nbsp;&nbsp; <a href="https://github.com/shdwjk/TheAaronSheet/blob/mast" rel="nofollow">https://github.com/shdwjk/TheAaronSheet/blob/mast</a>... // By:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The Aaron, Arcane Scriptomancer // Contact:&nbsp; <a href="https://github.com/shdwjk/TheAaronSheet/blob/mast" rel="nofollow">https://github.com/shdwjk/TheAaronSheet/blob/mast</a>... var TAS = TAS || (function(){ &nbsp;&nbsp;&nbsp; 'use strict'; &nbsp;&nbsp;&nbsp; var version = '0.2.3', &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lastUpdate = 1457014728, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; loggingSettings = { and then ends with the // &lt;********** snipped out the rest of TheAaron's code **********&gt; /* ---- END: TheAaronSheet.js ---- */ on('change:repeating_equipment', function(){ &nbsp;&nbsp;&nbsp; TAS.repeating('equipment') &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .attrs('totalequipmentweight','totalequipmentcost','summary') &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .fields('equipmentname','equipmentquantity','equipmentweight','equipmenttotalweight','equipmentcost','equipmenttotalcost') &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .reduce(function(m,r){ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m.equipmentweight+=(r.F.equipmentweight*r.I.equipmentquantity); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; r.D[3].equipmenttotalweight=(r.F.equipmentweight*r.I.equipmentquantity); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m.equipmentcost+=(r.F.equipmentcost*r.I.equipmentquantity); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; r.D[2].equipmenttotalcost=(r.F.equipmentcost*r.I.equipmentquantity); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m.desc.push(r.equipmentname+(r.I.equipmentquantity&gt;1 ? ' (x'+r.S.equipmentquantity+')' : '')); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return m; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; },{equipmentweight:0,equipmentcost:0, desc: []},function(m,r,a){ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a.summary=m.desc.join(', '); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a.D[3].totalequipmentweight=m.equipmentweight; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a.D[2].totalequipmentcost=m.equipmentcost; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .execute(); }); // &lt;***********a few other things snipped out**********&gt; &lt;/script&gt; You can find TAS here:&nbsp; <a href="https://github.com/shdwjk/TheAaronSheet" rel="nofollow">https://github.com/shdwjk/TheAaronSheet</a> on the 3.5 sheet, I just grabbed the stuff inside TheAaronSheet.js and plugged that into my code and then used his examples to make the onchange function where I call it. Maybe I should update my TAS to the latest; I see he's got a slightly newer version... :)
1501957511
Pat S.
Forum Champion
Sheet Author
Yes I have it inside the script tags like shown.
1501958962

Edited 1501959061
[Deleted]
Sheet Author
&lt;div&gt;&lt;input type="number" name="attr_inventory_weight" title="Total of your equipment Worn and Carried" value="0" disabled="disabled"&gt;&lt;/div&gt; &lt;div&gt;&lt;input type="number" name="attr_coin_weight" value="((@{CP} + @{SP} + @{GP})/10)" disabled="disabled"&gt;&lt;/div&gt; &lt;div&gt;&lt;input type="number" name="attr_other_weight" value="0" min="0"&gt;&lt;/div&gt; &lt;div&gt;&lt;input type="number" name="attr_total_weight" value="@{inventory_weight} + @{coin_weight} + @{other_weight}" disabled="disabled"&gt;&lt;/div&gt; &lt;/div&gt; &lt;h4&gt;Equipment &lt;/h4&gt; &lt;input type="radio" name="attr_inventorytab" value="1" title="Page 1" checked="checked" /&gt; &lt;span&gt;On Person&lt;/span&gt; &lt;!-- Inventory Page 1--&gt; &lt;div&gt; &lt;input type="text" name="attr_tabinvtitle1" value="What is being worn or carried on person " disabled="disabled"&gt; &lt;div&gt; &lt;div&gt;Name&lt;/div&gt; &lt;div&gt;Qty&lt;/div&gt; &lt;div&gt;Weight&lt;/div&gt; &lt;div&gt;Notes&lt;/div&gt; &lt;/div&gt; &lt;fieldset&gt; &lt;div&gt; &lt;div&gt;&lt;input type="text" name="attr_itemname"&gt;&lt;/div&gt; &lt;div&gt;&lt;input type="number" name="attr_itemquantity"&gt;&lt;/div&gt; &lt;div&gt;&lt;input type="number" name="attr_itemwornenc"&gt;&lt;/div&gt; &lt;div&gt;&lt;input type="text" name="attr_itemdesc"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/fieldset&gt; &lt;/div&gt; I added a value="0" so that it has a baseline number to watch. This isn't actually necessary, but I find it helps when looking for changes. I tested this using a mock-up of what you provided and this works for me. Edit: The ['name'] only has to used for attribute that have a - symbol in them. such as ['gear-weight'] where gearweight does not require it. &lt;!--inventory weight calculation--&gt; // Equipment Carried Section on('change:repeating_inventtab1', function(){ TAS.repeating('inventtab1') .attrs('inventory_weight') .fields('itemwornenc', 'itemquantity') .reduce(function(m,r){ m.itemwornenc+=(r.F.itemwornenc*r.I.itemquantity); r.D[0].inventory_weight=(r.F.itemwornenc*r.I.itemquantity) return m; },{itemwornenc:0,itemquantity:0, desc: []}, function (m,r,a){ a.inventory_weight=m.itemwornenc; }) .execute(); })
1501960393
Diana P
Pro
Sheet Author
I would also point out that it looks to me like this line: r.D[0].inventory_weight=(r.F.itemwornenc*r.I.itemquantity) is missing a semi-colon (;) at the end, but my scripting is poor enough that I don't know if it makes a difference or not.
1501960973

Edited 1501960991
Jakob
Sheet Author
API Scripter
Diana P said: I would also point out that it looks to me like this line: r.D[0].inventory_weight=(r.F.itemwornenc*r.I.itemquantity) is missing a semi-colon (;) at the end, but my scripting is poor enough that I don't know if it makes a difference or not. It's bad practice not to end a line with a semicolon, but it's not actually a syntax (or semantical) error unless you're running in strict mode (but you should always be running in strict mode).
1501961514
Pat S.
Forum Champion
Sheet Author
What does the m,r,a mean? I see it in the code such as reduce(function(m,r) It is functioning partially. For some reason it is not showing in the encumbrance display but the total display where the coins and equipment is added together but that uses a different attr name which is puzzling me. I have not put the value="0" in the code yet. I want to see something show up first.
1501973275
Pat S.
Forum Champion
Sheet Author
I have broken the script multiple times while trying to get it to display the repeating fieldset weight total in equipment box instead of being added in the total box (see picture above) but I have not gotten it to change. It either adds to the total or it it doesn't do anything. Suggestions? Script at present &lt;!--inventory weight calculation--&gt; // Equipment Carried Section on('change:repeating_inventtab1', function(){ TAS.repeating('inventtab1') .attrs('inventory_weight') .fields('itemwornenc', 'itemquantity') .reduce(function(m,r){ m.itemwornenc+=(r.F.itemwornenc*r.I.itemquantity); r.D[0].inventory_weight=(r.F.itemwornenc*r.I.itemquantity); return m; },{itemwornenc:0,itemquantity:0, desc: []}, function (m,r,a){ a.inventory_weight=m.itemwornenc; }) .execute(); })
1501975423

Edited 1501975462
[Deleted]
Sheet Author
So, and this is just what I do in my sheet, but create a hidden attribute, like attr_tempweight and do something like this... &lt;div&gt;&lt;input style="display: hidden;" type="text" name="attr_tempweight" value="0"&gt;&lt;input type="number" name="attr_inventory_weight" title="Total of your equipment Worn and Carried" value="@{tempweight}" disabled="disabled"&gt;&lt;/div&gt; &lt;div&gt;&lt;input type="number" name="attr_coin_weight" value="((@{CP} + @{SP} + @{GP})/10)" disabled="disabled"&gt;&lt;/div&gt; &lt;div&gt;&lt;input type="number" name="attr_other_weight" value="0" min="0"&gt;&lt;/div&gt; &lt;div&gt;&lt;input type="number" name="attr_total_weight" value="@{inventory_weight} + @{coin_weight} + @{other_weight}" disabled="disabled"&gt;&lt;/div&gt; &lt;/div&gt; &lt;h4&gt;Equipment &lt;/h4&gt; &lt;input type="radio" name="attr_inventorytab" value="1" title="Page 1" checked="checked" /&gt; &lt;span&gt;On Person&lt;/span&gt; &lt;!-- Inventory Page 1--&gt; &lt;div&gt; &lt;input type="text" name="attr_tabinvtitle1" value="What is being worn or carried on person " disabled="disabled"&gt; &lt;div&gt; &lt;div&gt;Name&lt;/div&gt; &lt;div&gt;Qty&lt;/div&gt; &lt;div&gt;Weight&lt;/div&gt; &lt;div&gt;Notes&lt;/div&gt; &lt;/div&gt; &lt;fieldset&gt; &lt;div&gt; &lt;div&gt;&lt;input type="text" name="attr_itemname"&gt;&lt;/div&gt; &lt;div&gt;&lt;input type="number" name="attr_itemquantity"&gt;&lt;/div&gt; &lt;div&gt;&lt;input type="number" name="attr_itemwornenc"&gt;&lt;/div&gt; &lt;div&gt;&lt;input type="text" name="attr_itemdesc"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/fieldset&gt; &lt;/div&gt; &lt;!--inventory weight calculation--&gt; // Equipment Carried Section on('change:repeating_inventtab1', function(){ TAS.repeating('inventtab1') .attrs('tempweight') .fields('itemwornenc', 'itemquantity') .reduce(function(m,r){ m.itemwornenc+=(r.F.itemwornenc*r.I.itemquantity); r.D[0].tempweight=(r.F.itemwornenc*r.I.itemquantity); return m; },{itemwornenc:0,itemquantity:0, desc: []}, function (m,r,a){ a.tempweight=m.itemwornenc; }) .execute(); }) In this manner, it uses the hidden box for calculations, but after rendering said calculations, passes the totaled value onto the visible box. I don't know that this is even necessary, but I got into the habit of doing it because I accidentally got it working the first time by doing so.
1501976290
Pat S.
Forum Champion
Sheet Author
I tried the hidden box but I apparently messed it up as yours looks different than what I tried to do. I will try yours before I break my table with my head from beating on it.
ack, try this actually (just looked at mine instead of trying to type off of memory) &lt;div&gt;&lt;input style="display: none ;" type="text" name="attr_tempweight" value="0"&gt;&lt;input type="number" name="attr_inventory_weight" title="Total of your equipment Worn and Carried" value="@{tempweight}" disabled="disabled"&gt;&lt;/div&gt; &lt;div&gt;&lt;input type="number" name="attr_coin_weight" value="((@{CP} + @{SP} + @{GP})/10)" disabled="disabled"&gt;&lt;/div&gt; &lt;div&gt;&lt;input type="number" name="attr_other_weight" value="0" min="0"&gt;&lt;/div&gt; &lt;div&gt;&lt;input type="number" name="attr_total_weight" value="@{inventory_weight} + @{coin_weight} + @{other_weight}" disabled="disabled"&gt;&lt;/div&gt; &lt;/div&gt; &lt;h4&gt;Equipment &lt;/h4&gt; &lt;input type="radio" name="attr_inventorytab" value="1" title="Page 1" checked="checked" /&gt; &lt;span&gt;On Person&lt;/span&gt; &lt;!-- Inventory Page 1--&gt; &lt;div&gt; &lt;input type="text" name="attr_tabinvtitle1" value="What is being worn or carried on person " disabled="disabled"&gt; &lt;div&gt; &lt;div&gt;Name&lt;/div&gt; &lt;div&gt;Qty&lt;/div&gt; &lt;div&gt;Weight&lt;/div&gt; &lt;div&gt;Notes&lt;/div&gt; &lt;/div&gt; &lt;fieldset&gt; &lt;div&gt; &lt;div&gt;&lt;input type="text" name="attr_itemname"&gt;&lt;/div&gt; &lt;div&gt;&lt;input type="number" name="attr_itemquantity"&gt;&lt;/div&gt; &lt;div&gt;&lt;input type="number" name="attr_itemwornenc"&gt;&lt;/div&gt; &lt;div&gt;&lt;input type="text" name="attr_itemdesc"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/fieldset&gt; &lt;/div&gt;
1501977078
Pat S.
Forum Champion
Sheet Author
Thank you so much. It is working. You are a genius.
awesome, glad it's working :D
1501977620
Pat S.
Forum Champion
Sheet Author
Now I get to figure out how to build some sheetworkers to convert one of the inventory tabs over to another one as I'm combining two tabs into one.
1502498470

Edited 1502504737
Pat S.
Forum Champion
Sheet Author
moving this to an actual thread for the sheet.