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

Script Worker assistance required - RepeatingSum encumberance

1598082984
Steve
Plus
Sheet Author
Hi all, I am trying to use the RepeatingSum script worker from the wiki here:&nbsp; <a href="https://wiki.roll20.net/RepeatingSum#repeatingSum_Version_2" rel="nofollow">https://wiki.roll20.net/RepeatingSum#repeatingSum_Version_2</a> I can't get it to work, and I'm sure it's because I am not doing it right. Do I just copy/paste the whole chunk of code over, then change the first line:&nbsp; const repeatingSum = (destinations, section, fields, ...extras) = &gt; { to the values from my sheet (repeating section = inventoryitems, values to add = attr_encumberancevalue, output = attr_totalencumberance): const repeatingSum = (totalencumberance, inventoryitems, encumberancevalue) =&gt; { and leave the rest of the script code alone? Or do I have to edit the rest of it somehow? Or do I have to put in more code elsewhere?
1598091175

Edited 1598091582
Andreas J.
Forum Champion
Sheet Author
Translator
I'm pretty sure you're supposed to just copy that codeblock unedited, and then use&nbsp; one of the small codeblock that are sown under it to describe what you want to work with. Look at how I implemented the first RepeatSum version in the D6StarWars sheet into making a credit counter and a character point(cp) counter. The core codeblock is copied as is, and then I have these short ones at the bottom: on("change:repeating_credittable remove:repeating_credittable", function() { repeatingSum("credit_spent","credittable","credit_amount"); }); on("change:repeating_cptable change:repeating_cptable", function() { repeatingSum("cp_spent", "cptable","cp_amount");
1598093771

Edited 1598093873
GM
Pro
Hi there, I just got this working myself properly so I'm happy to try to help answer some questions on it.&nbsp; Some of the answers I got while figuring it out went a bit over my head so I think I see your problem from the fellow newbie perspective. My primary problem was I couldn't figure out how to actually make a Sheet Worker and was confused by the term, and tried to add the code into the JavaScript section instead.&nbsp; What you want to do is paste the entire block of code with &nbsp;&nbsp;&nbsp; &lt;script type="text/worker"&gt; and &lt;/script&gt; blocked around the script right in your HTML file.&nbsp; Then you need to paste the second sections that Andreas there mentioned to actually do things with it; the first block just allows the second section to function. Those added sections should be within the script worker and not a different one. From there, all you need to do is tinker with the attribute names but otherwise leave the code alone unless you need to modify it in some specific manner.
1598094611
Andreas J.
Forum Champion
Sheet Author
Translator
Master S. said: Hi there, I just got this working myself properly so I'm happy to try to help answer some questions on it.&nbsp; Some of the answers I got while figuring it out went a bit over my head so I think I see your problem from the fellow newbie perspective. My primary problem was I couldn't figure out how to actually make a Sheet Worker and was confused by the term, and tried to add the code into the JavaScript section instead.&nbsp; You should take a new look at the main <a href="https://wiki.roll20.net/Sheetworkers" rel="nofollow">https://wiki.roll20.net/Sheetworkers</a> wiki page, I've recently expanded &amp; update the "Basics"-explanation sections on it that gives a rundown on what they are, how and where they are used, and the main way they are structured. There are also tons of new links to practical examples of sheetworkers both simple and more complex.
1598119541
GiGs
Pro
Sheet Author
API Scripter
I'm the writer of repeatingSum, and questions like this are telling me I need to include a better introductory description - even if that's just to point at Andreas's excellently maintained sheetworkers page. You definitely aren't the first to be confused about how to set it up. Andreas and Master S both give good advice. To get specific: MedievalSteve said: Do I just copy/paste the whole chunk of code over, then change the first line:&nbsp; You copy the whole chunk over, into a script block ,and change nothing . Do not change anything with that block of code. Instead you follow it with sheet workers that do the work you want, and they work because that block of code is there. They look like the things Andreas posted. You wrote this: &nbsp;the values from my sheet (repeating section = inventoryitems, values to add = attr_encumberancevalue, output = attr_totalencumberance): That suggests you have at least one problem, possibly two, to fix before you can use this code. First, when calling attributes, you never &nbsp;use the attr_ part. That is not part of the attribute name. This mistake is perfectly understandable, roll20's naming conventions are confusing. But when you name an attribute with something like name="attr_ totalencumbrance " the bit in bold is the attribute name. The attr_ part is a flag to alert roll20 that this name is an attribute name. You can also have roll button names, and action button names which look like name="roll_ totalencumbrance " name="act_ totalencumbrance " That first bit up the underscore is never actually used by you - its only there to identify to roll20 the kind of name it is. Secondly, sheet workers and autocalc fields are incombatible. I mention this on the off-chance that your encumberancevalue attribute is an autocalc field. If not, you can ignore it. An autocalc field is a calculated value that looks something like &lt;input type="number" name="encumberancevalue" value="@{weight}*@{number}" disabled="true" /&gt; That disabled part is key - sheet workers cannot do anything with disabled attributes, and you'd need to change that to a normal attribute, and calculate the value with a sheet worker. Luckily though, repeatingSum can do that for you. So, if encumberancevalue is NOT a disabled attribute, you would do that after copying in that big script from the repeatingSum page: on("change:repeating_credittable remove:repeating_credittable", function() { repeatingSum("totalencumberance", "inventoryitems", "encumberancevalue"); }); If it is a disabled value, and you have separate weight and amount (for example) attributes, you replace the encumbrancevalue above with both of them inside square brackets, like this on("change:repeating_credittable remove:repeating_credittable", function() { repeatingSum("totalencumberance", "inventoryitems", ["weight", "amount"]); }); Hope that helps.
📜🗡Andreas J.🏹📜 said: Master S. said: Hi there, I just got this working myself properly so I'm happy to try to help answer some questions on it.&nbsp; Some of the answers I got while figuring it out went a bit over my head so I think I see your problem from the fellow newbie perspective. My primary problem was I couldn't figure out how to actually make a Sheet Worker and was confused by the term, and tried to add the code into the JavaScript section instead.&nbsp; You should take a new look at the main <a href="https://wiki.roll20.net/Sheetworkers" rel="nofollow">https://wiki.roll20.net/Sheetworkers</a> wiki page, I've recently expanded &amp; update the "Basics"-explanation sections on it that gives a rundown on what they are, how and where they are used, and the main way they are structured. There are also tons of new links to practical examples of sheetworkers both simple and more complex. This is an incredibly helpful resource, thanks!&nbsp; Going over it now.
1598128616
GiGs
Pro
Sheet Author
API Scripter
In roll20, everything inside the script block is javascript. Sheet Workers are a specific type of javascript that start with on( . You can think of them as watchers, little bits of code that are watching a sheet for changes. When specific changes happen (those listed inside the on() &nbsp;part), they spring into action and do something.&nbsp;
1598161679
Steve
Plus
Sheet Author
Guys this advice was awesome, thank you for taking the time to assist me. I also appreciate you guys coding and distributing the scripts in the first place! Cheers GiGs and Andreas J! Following your advice, I still made a couple of mistakes that were blocking the script from totalling properly: 1) I had put each of the scripts into their own &lt;script type=text/worker&gt;&lt;/script&gt; brackets, I didn't realise they should all be in between the same backets. 2) I had the totalencumberance value attached to a number box on the sheet, the script wouldn't work until I made the totalencumberance attribute a 'hidden' value. Here's what I ended up with (I really should use spellcheck on my code...): &nbsp; &nbsp; &nbsp; &nbsp;&lt;div class="inventory"&gt; &lt;div class="posessions"&gt; &lt;input type="hidden" name="attr_totalencumberance" /&gt; &lt;label&gt;Posessions&lt;/label&gt; &lt;fieldset class="repeating_InventoryItems"&gt; Item &lt;input class="sixteenlongtextinput" type="text" name="attr_InventoryItem" /&gt; Location &lt;input class="twelvemidlongtextinput" type="text" name="attr_ItemLocation" /&gt; Encumberance &lt;input type="number" name="attr_EncumberanceValue" /&gt; &lt;/fieldset&gt; &lt;label&gt;Total Encumberance&lt;/label&gt; &lt;/div&gt; &lt;div class="money"&gt; &lt;label&gt;Cash on hand&lt;/label&gt; &lt;label&gt;Crowns &lt;input type="number" name="attr_GC" /&gt; Florins &lt;input type="number" name="attr_SF" /&gt; Pennies &lt;input type="number" name="attr_CP" /&gt; &lt;/label&gt; &lt;label&gt;Other wealth&lt;/label&gt; &lt;textarea name="attr_OtherWealth"&gt;&lt;/textarea&gt; &lt;/div&gt; and on("change:repeating_inventoryitems remove:repeating_inventoryitems change:gc, change:sf, change:cp", function() { repeatingSum("totalencumberance", "inventoryitems", "encumberancevalue", "gc:1/150, sf:1/150, cp:1/150"); }); Now the totalencumberance attribute properly adds up all the inventory items. However, it does not add in the weight of the coins (150 coins of any denomination = 1 encumbrance point). Where am I going wrong with the coins?
1598167422
GiGs
Pro
Sheet Author
API Scripter
totalencumbrance should be fine as a number field, it doesnt need to be hidden. Just change the type, don't change anything else. With your coinage values, you've put them all in a single set of quotes- each should be in its own set of quotes, like so: repeatingSum("totalencumberance", "inventoryitems", "encumberancevalue", "gc:1/150", "sf:1/150", "cp:1/150");
1598168391
Steve
Plus
Sheet Author
Thanks GiGs, you've cracked it. Could not have done this without your help, I was tearing my hair out!
1598172623
GiGs
Pro
Sheet Author
API Scripter
Yay!&nbsp;