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

RepeatingSum problems

1545892914

Edited 1545893202
Hi, I have a problem with the repeating sum function as can be seen here:&nbsp; <a href="https://wiki.roll20.net/RepeatingSum" rel="nofollow">https://wiki.roll20.net/RepeatingSum</a> I am using it in my character sheet five times. An all five work like a charm. For the sixth, I've copypasted the code from one of the earlier uses in the same character sheet, adjusted the attribute names and...it ain't working. And I don't know why.&nbsp; To give you a little background: I am trying to include the Pathfinder Kingdom Building Rules in my character sheet. Here's the beginning of the fieldset &lt;fieldset class="repeating_cityBuildings"&gt; &lt;div class="sheet-margin-bottom sheet-padr sheet-padl"&gt; &lt;div class="sheet-row"&gt; &lt;div class="sheet-col-1-23 sheet-vert-middle sheet-left"&gt; &lt;input type="checkbox" name="attr_PropertyUsed" value="1" title="Property used" /&gt; &lt;/div&gt; &lt;div class="sheet-col-1-14 sheet-vert-middle sheet-left"&gt; &lt;input class="inSmallNum_noBorder" type="number" name="attr_cityBuildingAmount" value="0" step="1" min="0" title="cityBuildingAmount"&gt; &lt;/div&gt; &lt;div class="sheet-col-1-3 sheet-vert-middle"&gt; &lt;input type="text" class="sheet-inMainTxt" name="attr_cityBuildingName" placeholder="City Building"&gt; &lt;/div&gt; &lt;div class="sheet-cityBuildingProperties"&gt; &lt;div class="sheet-col-1-14 sheet-vert-middle sheet-center"&gt; &lt;input class="inSmallNum_noBorder" type="number" name="attr_cityBuildingEconomy" value="0" step="1" min="-10" max="10" title="cityBuildingEconomy"&gt; &lt;/div&gt; &lt;div class="sheet-col-1-14 sheet-vert-middle sheet-center"&gt; &lt;input class="inSmallNum_noBorder" type="number" name="attr_cityBuildingStability" value="0" step="1" min="-10" max="10" title="cityBuildingStability"&gt; &lt;/div&gt; &lt;div class="sheet-col-1-14 sheet-vert-middle sheet-center"&gt; &lt;input class="inSmallNum_noBorder" type="number" name="attr_cityBuildingLoyality" value="0" step="1" min="-10" max="10" title="cityBuildingLoyality"&gt; &lt;/div&gt; &lt;div class="sheet-col-1-14 sheet-vert-middle sheet-center"&gt; &lt;input class="inSmallNum_noBorder" type="number" name="attr_cityBuildingUpkeep" value="0" step="1" min="-10" max="10" title="cityBuildingUpkeep"&gt; &lt;/div&gt; &lt;div class="sheet-col-1-14 sheet-vert-middle sheet-center"&gt; &lt;input class="inSmallNum_noBorder" type="number" name="attr_cityBuildingUnrest" value="0" step="1" min="-10" max="10" title="cityBuildingUnrest"&gt; &lt;/div&gt; &lt;div class="sheet-col-1-14 sheet-vert-middle sheet-center"&gt; &lt;input class="inSmallNum_noBorder" type="number" name="attr_cityBuildingLore" value="0" step="1" min="-10" max="10" title="cityBuildingLore"&gt; &lt;/div&gt; &lt;div class="sheet-col-1-14 sheet-vert-middle sheet-center"&gt; &lt;input class="inSmallNum_noBorder" type="number" name="attr_cityBuildingLaw" value="3" step="1" min="-10" max="10" title="cityBuildingLaw"&gt; &lt;/div&gt; There are more fields and of course I close the div and the fieldset (adding values in the character sheet works just fine) but that is just to show how it's setup. Then there's the code summary field: &lt;div class="sheet-col-2-10 sheet-savingthrow-num sheet-vert-middle"&gt; &lt;input type="text" name="attr_cityTotalLaw" class="sheet-savingthrow-num" title="Law" value="(5 + (@{cityLaw}))" disabled="disabled" /&gt; &lt;/div&gt; and btw. when I use value in the above mode, I get&nbsp;(5 + ()) in the attribute field. If I change it to ( (@{cityLaw})+5) I get 5 instead. And finally the JS code at the bottom of the file. on('change:repeating_cityBuildings remove:repeating_cityBuildings', function() { repeatingSum("cityEconomy","cityBuildings","cityBuildingEconomy","cityBuildingAmount"); repeatingSum("cityStability","cityBuildings","cityBuildingStability","cityBuildingAmount"); repeatingSum("cityLoyality","cityBuildings","cityBuildingLoyality","cityBuildingAmount"); repeatingSum("cityUpkeep","cityBuildings","cityBuildingUpkeep","cityBuildingAmount"); repeatingSum("cityUnrest","cityBuildings","cityBuildingUnrest","cityBuildingAmount"); repeatingSum("cityLore","cityBuildings","cityBuildingLore","cityBuildingAmount"); repeatingSum("cityLaw","cityBuildings","cityBuildingLaw","cityBuildingAmount"); repeatingSum("citySociety","cityBuildings","cityBuildingSociety","cityBuildingAmount"); repeatingSum("cityProductivity","cityBuildings","cityBuildingProductivity","cityBuildingAmount"); repeatingSum("cityDanger","cityBuildings","cityBuildingDanger","cityBuildingAmount"); repeatingSum("cityCrime","cityBuildings","cityBuildingCrime","cityBuildingAmount"); repeatingSum("cityCorruption","cityBuildings","cityBuildingCorruption","cityBuildingAmount"); repeatingSum("cityDefense","cityBuildings","cityBuildingDefense","cityBuildingAmount"); repeatingSum("citySpace","cityBuildings","cityBuildingSpace","cityBuildingAmount"); }); (I didn't copy the other JS for RepeatingSum in here as it is a 1:1 copy and as I said, works the five other times in that character sheet.) And yes, I have created fieldset entries with values different from 0. It looks OK to me but my character sheet tells me otherwise. Yet, I can't find the problem.
1545898320

Edited 1545898409
vÍnce
Pro
Sheet Author
Not sure if it makes a difference in your case , but you should keep your on('change...') attribute names in lowercase regardless of the actual attribute's name.&nbsp; There's a blurb on the sheetworker wiki about it.
1545902271
GiGs
Pro
Sheet Author
API Scripter
Thats a neat way to use the script. I cant see at a glance what the issue is, than as Vince says (complete with clever pun), change statements should be in lower case. What do you get if you type @{SHEETNAME GOES HERE|cityLaw} in local chat? (Change the all caps to the sheet name). If the case issue isnt the problem, I suggest removing all but one of the repeatingsum lines and see if it works. Try them all individually and see if any of them work. If none of them work, we'll need to do more digging, but if some do and some don't, we can investigate the ones that dont work to find out why.
1545902982

Edited 1545903191
GiGs
Pro
Sheet Author
API Scripter
Is this the issue: you use this line: repeatingSum(" cityLaw ","cityBuildings","cityBuildingLaw","cityBuildingAmount"); But the summary field is not cityLaw , it is cityTotalLaw . &lt;input type="text" name=" attr_cityTotalLaw " Edit: scratch that, I see it calls cityLaw. Do you have cityLaw defined in the sheet, and if so, how? It must not be a disabled field.&nbsp; Why is there a cityLaw (which appears to be the total) and a separate cityTotalLaw?
Case shouldn't be a problem. I have used it before and it worked like a charm, e.g. on('change:repeating_armyTactics remove:repeating_armyTactics', function() { repeatingSum("armyTacticsTotalOM ","armyTactics ","armyTacticOM ","armyTacticUsed "); repeatingSum("armyTacticsTotalDV ","armyTactics ","armyTacticDV ","armyTacticUsed "); repeatingSum("armyTacticsTotalMorale ","armyTactics ","armyTacticMorale ","armyTacticUsed "); repeatingSum("armyTacticsTotalDamage ","armyTactics ","armyTacticDamage ","armyTacticUsed "); }); Nevertheless, I've tried it but again, nothing. If you want to have a look at the entire code you can find it here:&nbsp; <a href="http://jsfiddle.net/j4g672hu/" rel="nofollow">http://jsfiddle.net/j4g672hu/</a> It is based on Moldvay's ODnD sheet. However, my players want warmachine rules and I like the Pathfinder ones better. That's why I came up with this bastard.&nbsp;
PS: I am calling&nbsp; cityTotalLaw &nbsp;because I don't know if the system likes self-referencing. Plus, it allows me to add other fieldsets later on, which might also contain a bonus. You can see this with the army sheet.
1545907793
GiGs
Pro
Sheet Author
API Scripter
I loaded the sheet and used f12 to open the console, and there a LOT of errors been reported. This is just the start of them: Are you sure everything else is working fine, and the problem is limited to just this sheet worker?
1545907923
GiGs
Pro
Sheet Author
API Scripter
Rouven said: PS: I am calling&nbsp; cityTotalLaw &nbsp;because I don't know if the system likes self-referencing. Plus, it allows me to add other fieldsets later on, which might also contain a bonus. You can see this with the army sheet. You dont need to do that. In fact, it would be much better to change that attribute to&nbsp; &lt;input type="text" name="attr_cityLaw" class="sheet-savingthrow-num" title="Law" value="0" readonly /&gt; You could keep the name cityTotalLaw, but if so, change cityLaw in the sheet worker to cityTotalLaw. There's no need to use an intermediate attribute the way you are doing here.
1545909741

Edited 1545910540
GiGs
Pro
Sheet Author
API Scripter
Vince was right: the issue is the capital letters in the change statement. The wiki is the law when it comes to how to create character sheets: don't deviate from the rules it sets. Using uppercase letters on the change line may appear &nbsp;to work some of the time, but it's inconsistent - you'll have errors you aren't aware of. I went through all your sheet workers, changed ALL the capitals to lower case (only on the change line), and lo and behold, the sheet workers worked. Unrelated, but for better practices, i also changed the inputs in the city section to this format: &lt;input type="text" name="attr_cityTotalDefense" class="sheet-savingthrow-num" title="Defense" value="0" readonly/&gt; You need to remove the autocalc calculation and disabled; readonly makes it so players cant alter it but scripts can. And the sheet worker itself to use the Total naming: on('change:repeating_citybuildings remove:repeating_citybuildings', function() { &nbsp; &nbsp; repeatingSum("cityTotalEconomy","cityBuildings","cityBuildingEconomy","cityBuildingAmount"); repeatingSum("cityTotalStability","cityBuildings","cityBuildingStability","cityBuildingAmount"); repeatingSum("cityTotalLoyality","cityBuildings","cityBuildingLoyality","cityBuildingAmount"); repeatingSum("cityTotalUpkeep","cityBuildings","cityBuildingUpkeep","cityBuildingAmount"); repeatingSum("cityTotalUnrest","cityBuildings","cityBuildingUnrest","cityBuildingAmount"); repeatingSum("cityTotalLore","cityBuildings","cityBuildingLore","cityBuildingAmount"); repeatingSum("cityTotalLaw","cityBuildings","cityBuildingLaw","cityBuildingAmount"); repeatingSum("cityTotalSociety","cityBuildings","cityBuildingSociety","cityBuildingAmount"); repeatingSum("cityTotalProductivity","cityBuildings","cityBuildingProductivity","cityBuildingAmount"); repeatingSum("cityTotalDanger","cityBuildings","cityBuildingDanger","cityBuildingAmount"); repeatingSum("cityTotalCrime","cityBuildings","cityBuildingCrime","cityBuildingAmount"); repeatingSum("cityTotalCorruption","cityBuildings","cityBuildingCorruption","cityBuildingAmount"); repeatingSum("cityTotalDefense","cityBuildings","cityBuildingDefense","cityBuildingAmount"); repeatingSum("cityTotalSpace","cityBuildings","cityBuildingSpace","cityBuildingAmount"); }); To bypass the unneeded intermediate attribute. It works perfectly.
1545909980
GiGs
Pro
Sheet Author
API Scripter
To simplify copy and paste, this what i changed all the sheet workers to. Note: you don't need the TAS script at the start of your script section. You can delete that completely. on('change:repeating_armytactics remove:repeating_armytactics', function() { repeatingSum("armyTacticsTotalOM","armyTactics","armyTacticOM","armyTacticUsed"); repeatingSum("armyTacticsTotalDV","armyTactics","armyTacticDV","armyTacticUsed"); repeatingSum("armyTacticsTotalMorale","armyTactics","armyTacticMorale","armyTacticUsed"); repeatingSum("armyTacticsTotalDamage","armyTactics","armyTacticDamage","armyTacticUsed"); }); on('change:repeating_armyresources remove:repeating_armyresources', function() { repeatingSum("armyResourcesTotalOM","armyResources","armyResourceOM"); repeatingSum("armyResourcesTotalDV","armyResources","armyResourceDV"); repeatingSum("armyResourcesTotalMorale","armyResources","armyResourceMorale"); repeatingSum("armyResourcesTotalDamage","armyResources","armyResourceDamage"); }); on('change:repeating_armyspecialpowers remove:repeating_armyspecialpowers', function() { repeatingSum("armyPowersTotalOM","armySpecialPowers","armySpecialPowerOM"); repeatingSum("armyPowersTotalDV","armySpecialPowers","armySpecialPowerDV"); repeatingSum("armyPowersTotalMorale","armySpecialPowers","armySpecialPowerMorale"); repeatingSum("armyPowersTotalDamage","armySpecialPowers","armySpecialPowerDamage"); }); on('change:repeating_armyconditions remove:repeating_armyconditions', function() { repeatingSum("armyConditionsTotalOM","armyConditions","armyConditionOM","armyConditionUsed"); repeatingSum("armyConditionsTotalDV","armyConditions","armyConditionDV","armyConditionUsed"); repeatingSum("armyConditionsTotalMorale","armyConditions","armyConditionMorale","armyConditionUsed"); repeatingSum("armyConditionsTotalDamage","armyConditions","armyConditionDamage","armyConditionUsed"); }); on('change:repeating_armyboons remove:repeating_armyboons', function() { repeatingSum("armyBoonsTotalOM","armyBoons","armyBoonOM"); repeatingSum("armyBoonsTotalDV","armyBoons","armyBoonDV"); repeatingSum("armyBoonsTotalMorale","armyBoons","armyBoonMorale"); repeatingSum("armyBoonsTotalDamage","armyBoons","armyBoonDamage"); }); on('change:repeating_citybuildings remove:repeating_citybuildings', function() { &nbsp; &nbsp; repeatingSum("cityTotalEconomy","cityBuildings","cityBuildingEconomy","cityBuildingAmount"); repeatingSum("cityTotalStability","cityBuildings","cityBuildingStability","cityBuildingAmount"); repeatingSum("cityTotalLoyality","cityBuildings","cityBuildingLoyality","cityBuildingAmount"); repeatingSum("cityTotalUpkeep","cityBuildings","cityBuildingUpkeep","cityBuildingAmount"); repeatingSum("cityTotalUnrest","cityBuildings","cityBuildingUnrest","cityBuildingAmount"); repeatingSum("cityTotalLore","cityBuildings","cityBuildingLore","cityBuildingAmount"); repeatingSum("cityTotalLaw","cityBuildings","cityBuildingLaw","cityBuildingAmount"); repeatingSum("cityTotalSociety","cityBuildings","cityBuildingSociety","cityBuildingAmount"); repeatingSum("cityTotalProductivity","cityBuildings","cityBuildingProductivity","cityBuildingAmount"); repeatingSum("cityTotalDanger","cityBuildings","cityBuildingDanger","cityBuildingAmount"); repeatingSum("cityTotalCrime","cityBuildings","cityBuildingCrime","cityBuildingAmount"); repeatingSum("cityTotalCorruption","cityBuildings","cityBuildingCorruption","cityBuildingAmount"); repeatingSum("cityTotalDefense","cityBuildings","cityBuildingDefense","cityBuildingAmount"); repeatingSum("cityTotalSpace","cityBuildings","cityBuildingSpace","cityBuildingAmount"); });
1545910173

Edited 1545910280
GiGs
Pro
Sheet Author
API Scripter
I also noticed there were a lot of unnecessary spaces in attribute names. Lines like&nbsp; repeatingSum("armyResourcesTotalOM ","armyResources ","armyResourceOM "); which should be repeatingSum("armyResourcesTotalOM","armyResources","armyResourceOM"); I'm not sure if that was in your original code or an artifact of the copy to jsfiddle. But if its in the original, you need to be careful about that. Unnecessary spaces inside the quotes can cause a lot of scripts and sheet workers to fail.
Hm, that is strange. I don't get these errors. Yes, I have errors in my console but they are about loading mixed content (the two fonts) and not undefined variables. Also, I do get this strange value for a newly created character when I check the army sheet which hasn't been filled yet, e.g. Offensive Modifier field looks like this:&nbsp; ( + (6) +&nbsp; +&nbsp; +&nbsp; +&nbsp; +&nbsp; +(0) - (abs(2-2))) When I add entries in the different fieldsets the spaces get replaced by a 0 (or the respective values) and then it works. Nevertheless, I don't have a bunch of undefined variables coming up as error messages in my console. Hm, let's say it is the undefined variables. Where would I add them? In the "on change" statement? on('change:repeating_citybuildings remove:repeating_citybuildings', function() { var cityLaw = 0; repeatingSum("cityLaw","cityBuildings","cityBuildingLaw","cityBuildingAmount"); });
1545910820
GiGs
Pro
Sheet Author
API Scripter
The errors might just be because I havent set up any other stats outside the city buildings area, probably nothing to worry about. It's not the undefined variables, its the case. See my previous posts on how to fix it.
Yes, that's it. It is working now. Vince, GiGs thank you both very much for your help.
1545911381

Edited 1545911419
GiGs
Pro
Sheet Author
API Scripter
Rouven said: Also, I do get this strange value for a newly created character when I check the army sheet which hasn't been filled yet, e.g. Offensive Modifier field looks like this:&nbsp; ( + (6) +&nbsp; +&nbsp; +&nbsp; +&nbsp; +&nbsp; +(0) - (abs(2-2))) When I add entries in the different fieldsets the spaces get replaced by a 0 (or the respective values) and then it works. Nevertheless, I don't have a bunch of undefined variables coming up as error messages in my console. I forgot to reply to this: It looks like that because some attributes haven't been initialised - or have values that aren't numbers - so roll20's parser doesnt recognise it as a number until all the values exist. You might be able to fix it by giving all the attributes referred to a default value like value="0". You could also change it to a sheet worker instead of an autocalc field, and do the calculation there, and you can make sure it is always a valid number.
Okay, I took you up on the suggestion, thinking I might as well improve my character sheet while learning a thing or two. So I've set up a sheet worker for the Army sheet, more specifically the OM only. The field formerly looked like this and worked fine with the autocalculation. &lt;input type="text" name="attr_armytotalacr" class="sheet-savingthrow-num" title="Offensive Modifier" value="(@{armyBCR} + (@{armySize}) + @{armyTacticsTotalOM} + @{armyResourcesTotalOM} + @{armyPowersTotalOM} + @{armyConditionsTotalOM} + @{armyBoonsTotalOM} +(@{armyStance}) - (abs(@{armyAlignment}-@{armyCommanderAlignment})))" disabled="disabled" /&gt; Then I replaced it with this &lt;input type="text" name="attr_armytotalacr" class="sheet-savingthrow-num" title="Offensive Modifier" value="0" readonly /&gt; and finally the sheet worker. on("sheet:opened change:armybcr change:armysize change:repeating_armytactics remove:repeating_armytactics change:repeating_armyresources remove:repeating_armyresources change:repeating_armyspecialpowers remove:repeating_armyspecialpowers change:repeating_armyconditions remove:repeating_armyconditions change:repeating_armyboons remove:repeating_armyboons", function() { getAttrs(["armybcr", "armysize", "armytacticstotalom", "armyresourcestotalom", "armypowerstotalom", "armyconditionstotalom", "armyboonstotalom", "armystance", "armyalignment", "armycommanderalignment"], function(values) { var armybcr = parseInt(values["armyBCR"],10)||0; var armysize = parseInt(values["armySize"],10)||0; var armytacticstotalom = parseInt(values["armyTacticsTotalOM"],10)||0; var armyresourcestotalom = parseInt(values["armyResourcesTotalOM"],10)||0; var armypowerstotalom = parseInt(values["armyPowersTotalOM"],10)||0; var armyconditionstotalom = parseInt(values["armyConditionsTotalOM"],10)||0; var armyboonstotalom = parseInt(values["armyBoonsTotalOM"],10)||0; var armystance = parseInt(values["armyStance"],10)||0; var armyalignment = parseInt(values["armyAlignment"],10)||0; var armycommanderalignment = parseint(values["armyCommanderAlignment"],10)||0; var output = armybcr + armysize + armytacticstotalom + armyresourcestotalom + armypowerstotalom + armyconditionstotalom + armyboonstotalom + armystance + Math.abs(armyalignment-armycommanderalignment); setAttrs({ armytotalacr: output }); }); }); Oddly enough, this is the result I get in the attribute field: (@{armyBCR} + (@{armySize}) + @{armyTacticsTotalOM} + @{armyResourcesTotalOM} + @{armyPowersTotalOM} + @{armyConditionsTotalOM} + @{armyBoonsTotalOM} +(@{armyStance}) - (abs(@{armyAlignment}-@{armyCommanderAlignment})))
1545927257

Edited 1545927397
GiGs
Pro
Sheet Author
API Scripter
I think the attribute is still using the formula that was stored in the value when it was an autocalc field, which suggests the sheetworker either isn't running, or isn't recognising that attribute. So, a first step: look for the&nbsp;armytotalacr on the third character sheet tab: Attributes and Abilities. It'll be in the Attributes list somewhere. Find it and delete it. Don't worry, on the next sheet reopen, it will be recreated with default value. You can also try creating a completely new character and see if the same thing happens. Then to get the sheet worker working, I can think of a couple of possibilities. The first is case again. One of the frustrating things about roll20's model is that you need to use lower case for the On:change: line, but everywhere else you should use the original case. Your getAttrs statement is all lower case, you'll need to change that to match the original case as you have with the&nbsp;parseInt lines.&nbsp; (Incidentally I think this is why the new character sheet creation guidelines recommend using all lower case for attribute names, to avoid this confusion.) So, that's one thing that might be the issue.&nbsp; Another possibility:&nbsp; Are any of the attributes above using autocalc fields to calculate their values? If so, you'll need to change them to use sheetworkers too, first. Sheetworkers and autocalc fields don't work together: sheet workers dont see the number, they see the formula as text.&nbsp; Final note: you don't need the remove: statement for attributes outside of repeating sections (it doesnt do anything, it's only for repeating section attributes).&nbsp; PS: The calculation part of your sheet worker looks good, so once the attributes are being detected properly it should work perfectly.
GiGs said: I think the attribute is still using the formula that was stored in the value when it was an autocalc field, which suggests the sheetworker either isn't running, or isn't recognising that attribute. So, a first step: look for the&nbsp;armytotalacr on the third character sheet tab: Attributes and Abilities. It'll be in the Attributes list somewhere. Find it and delete it. Don't worry, on the next sheet reopen, it will be recreated with default value. You can also try creating a completely new character and see if the same thing happens. I went with a new character and the OM shows as 0 which is better. However, still doesn't react to any changes. GiGs &nbsp;said: Then to get the sheet worker working, I can think of a couple of possibilities. The first is case again. One of the frustrating things about roll20's model is that you need to use lower case for the On:change: line, but everywhere else you should use the original case. Your getAttrs statement is all lower case, you'll need to change that to match the original case as you have with the&nbsp;parseInt lines.&nbsp; (Incidentally I think this is why the new character sheet creation guidelines recommend using all lower case for attribute names, to avoid this confusion.) So, that's one thing that might be the issue.&nbsp; I have changed it to this but still no change. on("sheet:opened change:armybcr change:armysize change:repeating_armytactics remove:repeating_armytactics change:repeating_armyresources remove:repeating_armyresources change:repeating_armyspecialpowers remove:repeating_armyspecialpowers change:repeating_armyconditions remove:repeating_armyconditions change:repeating_armyboons remove:repeating_armyboons", function() { &nbsp; getAttrs(["armyBCR", "armySize", "armyTacticsTotalOM", "armyResourcesTotalOM", "armyPowersTotalOM", "armyConditionsTotalOM", "armyBoonsTotalOM", "armyStance", "armyAlignment", "armyCommanderAlignment"], function(values) { &nbsp; var armybcr = parseInt(values["armyBCR"],10)||0; &nbsp; var armysize = parseInt(values["armySize"],10)||0; &nbsp; var armytacticstotalom = parseInt(values["armyTacticsTotalOM"],10)||0; &nbsp; var armyresourcestotalom = parseInt(values["armyResourcesTotalOM"],10)||0; &nbsp; var armypowerstotalom = parseInt(values["armyPowersTotalOM"],10)||0; &nbsp; var armyconditionstotalom = parseInt(values["armyConditionsTotalOM"],10)||0; &nbsp; var armyboonstotalom = parseInt(values["armyBoonsTotalOM"],10)||0; &nbsp; var armystance = parseInt(values["armyStance"],10)||0; &nbsp; var armyalignment = parseInt(values["armyAlignment"],10)||0; &nbsp; var armycommanderalignment = parseint(values["armyCommanderAlignment"],10)||0; &nbsp; var output = armybcr + armysize + armytacticstotalom + armyresourcestotalom + armypowerstotalom + armyconditionstotalom + armyboonstotalom + armystance + Math.abs(armyalignment-armycommanderalignment); &nbsp; setAttrs({ armytotalacr: output &nbsp; }); &nbsp; }); }); I hope this will satisfy the on change as well as case sensitive variable names in JS. GiGs &nbsp;said: Another possibility:&nbsp; Are any of the attributes above using autocalc fields to calculate their values? If so, you'll need to change them to use sheetworkers too, first. Sheetworkers and autocalc fields don't work together: sheet workers dont see the number, they see the formula as text.&nbsp; Final note: you don't need the remove: statement for attributes outside of repeating sections (it doesnt do anything, it's only for repeating section attributes).&nbsp; PS: The calculation part of your sheet worker looks good, so once the attributes are being detected properly it should work perfectly. None of these fields are using autocalc. armyBCR is a direct input value,&nbsp;armySize,&nbsp;armyStance,&nbsp;armyAlignment,&nbsp;armyCommanderAlignment are select fields with numeric value and the others are repeating sums calculated by the sheet worker.&nbsp; PS: I even went to make all the above variables lower case in all instances. Still no result.
1545932587

Edited 1545932605
GiGs
Pro
Sheet Author
API Scripter
I've spotted one problem. You don't have a complete list of attributes in your change and getAttrs lines. You shouldnt have the repeating stats in there. Just the attribute that is filled by the sumRepeating script. You also need to add a few missing attributes. So it should be (remove the line breaks - those are just there for easier reading). on("sheet:opened change:armybcr change:armysize change:armytacticstotalom change:armyresourcestotalom change:armypowerstotalom change:armyconditionstotalom change:armyboonstotalom change:armystance change:armyalignment change:armycommanderalignment",function() { &nbsp;I am not sure this is why its not working, but it does need fixing anyway. Is armyTotalACR capitalised like this in your character sheet. if so, change the setAttrs line in the worker to match: armyTotalACR: output You can add console.log statements to the script which will show up in the browser console (what you see when you press f12). Something like: on("sheet:opened change:armybcr change:armysize change:armytacticstotalom change:armyresourcestotalom change:armypowerstotalom change:armyconditionstotalom change:armyboonstotalom change:armystance change:armyalignment change:armycommanderalignment",function() { &nbsp; getAttrs(["armyBCR", "armySize", "armyTacticsTotalOM", "armyResourcesTotalOM", "armyPowersTotalOM", "armyConditionsTotalOM", "armyBoonsTotalOM", "armyStance", "armyAlignment", "armyCommanderAlignment"], function(values) { &nbsp; console.log("======================= worker started"); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var armybcr = parseInt(values["armyBCR"],10)||0; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log("======================= armybcr: " + armybcr); &nbsp; var armysize = parseInt(values["armySize"],10)||0; console.log("======================= armysize: " + armysize); &nbsp; var armytacticstotalom = parseInt(values["armyTacticsTotalOM"],10)||0; &nbsp; var armyresourcestotalom = parseInt(values["armyResourcesTotalOM"],10)||0; &nbsp; var armypowerstotalom = parseInt(values["armyPowersTotalOM"],10)||0; &nbsp; var armyconditionstotalom = parseInt(values["armyConditionsTotalOM"],10)||0; &nbsp; var armyboonstotalom = parseInt(values["armyBoonsTotalOM"],10)||0; &nbsp; var armystance = parseInt(values["armyStance"],10)||0; &nbsp; var armyalignment = parseInt(values["armyAlignment"],10)||0; &nbsp; var armycommanderalignment = parseint(values["armyCommanderAlignment"],10)||0; &nbsp; var output = armybcr + armysize + armytacticstotalom + armyresourcestotalom + armypowerstotalom + armyconditionstotalom + armyboonstotalom + armystance + Math.abs(armyalignment-armycommanderalignment); &nbsp; setAttrs({ armytotalacr: output &nbsp; }); &nbsp; }); }); And by doing his you can check to see the script is actually firing, and the variables are being set properly. If nothing at all shows up in the console log, the script isnt being triggered, so the problem isn't the script worker itself, the problem is somewhere else: for example, in the attributes (do they all exist?), or in a script before this one in the sheet workers section.
Okay, this is getting warmer. I went on to include a console log for all attributes and this is the result. ======================= worker started VM17:154 ======================= armybcr: 12 VM17:156 ======================= armysize: 6 VM17:158 ======================= armytacticstotalom: -5 VM17:160 ======================= armyresourcestotalom: 4 VM17:162 ======================= armypowerstotalom: 0 VM17:164 ======================= armyconditionstotalom: 3 VM17:166 ======================= armyboonstotalom: 0 VM17:168 ======================= armystance: -4 VM17:170 ======================= armyalignment: 2 as you can see&nbsp;armycommanderalignment and output are missing here. Both also should have a console log. And when taking a closer look at armycommanderalignment I see that my code says&nbsp; parseint&nbsp; instead of&nbsp; parseInt .&nbsp; And lo and behold, it is working. Thanks for holding my hand and guiding me in this error finding process.&nbsp;
1545941181

Edited 1545941250
GiGs
Pro
Sheet Author
API Scripter
you're welcome! javascript coding can be really frustrating, because typos are so easy to make, and so hard to spot! The lack of automatic error reports is really a pain.
Not sure if anyone ever uses it (well, I do) but I've added a rounding option to your repeating sum script and thought I share it here. &nbsp; &nbsp;//Summing up fieldsets &nbsp; &nbsp;/* ===== PARAMETERS ========== destination = the name of the attribute that stores the total quantity section = name of repeating fieldset, without the repeating_ quantity = the name of the field to be summed units (optional) = the name a field that multiplies quantity.&nbsp; &nbsp; &nbsp;Set as " false " or don't include this parameter, if ignored. If using a checkbox rather than a number input, set its value to 1. multiplytotal (optional) = a multiplier to every item in the fieldset. For instance, if summing coins, might want to multiply the final total by 0.02 (if each coin weighs 0.02). round (otional) = if you want to round your sum to the next upper (use "ceil") or lower (user "floor") integer. if set to "false" or left out the sum may be a float number */ let repeatingSum = function (destination, section, quantity, units, multiplytotal, round){ let multiplier = true; if (units === undefined || units === false || units === 'false') multiplier = false; if (multiplytotal === undefined) multiplytotal = 1; if (round === undefined || round === false || round === 'false') round = false; getSectionIDs(`repeating_${section}`, (idArray) =&gt; { const quantityFields = idArray.map(id =&gt; `repeating_${section}_${id}_${quantity}`); const unitFields = multiplier ? idArray.map(id =&gt; `repeating_${section}_${id}_${units}`) : []; getAttrs(quantityFields.concat(unitFields), (v) =&gt; { //console.log("=====v alues of v: "+ JSON.stringify(v) +"====="); let sumTotal = 0; const rowValues = quantityFields.map(attr =&gt; parseFloat(v[attr], 10) || 0); if(multiplier) { const rowMultiples = unitFields.map(attr =&gt; parseFloat(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); } sumTotal = sumTotal * multiplytotal; if (round == 'ceil') { sumTotal = Math.ceil(sumTotal); } if (round == 'floor') { sumTotal = Math.floor(sumTotal); } setAttrs({[destination]: sumTotal });&nbsp; &nbsp;&nbsp; }); }); }
1546057992
GiGs
Pro
Sheet Author
API Scripter
Nice! I originally had it rounding by default, but realised most situations this would be used were things like inventory, where fractional values were important. You should add a round = 'round' for rounding to nearest (Math.round()).
You are right. Here we go. &nbsp; &nbsp;//Summing up fieldsets &nbsp; &nbsp;/* ===== PARAMETERS ========== destination = the name of the attribute that stores the total quantity section = name of repeating fieldset, without the repeating_ quantity = the name of the field to be summed units (optional) = the name a field that multiplies quantity.&nbsp; &nbsp; &nbsp;Set as " false " or don't include this parameter, if ignored. If using a checkbox rather than a number input, set its value to 1. multiplytotal (optional) = a multiplier to every item in the fieldset. For instance, if summing coins, might want to multiply the final total by 0.02 (if each coin weighs 0.02). round (otional) = if you want to round your sum to the next upper (use "ceil"), or lower (use "floor"), or next (use "round") integer. if set to "false" or left out the sum may be a float number */ let repeatingSum = function (destination, section, quantity, units, multiplytotal, round){ let multiplier = true; if (units === undefined || units === false || units === 'false') multiplier = false; if (multiplytotal === undefined) multiplytotal = 1; if (round === undefined || round === false || round === 'false') round = false; getSectionIDs(`repeating_${section}`, (idArray) =&gt; { const quantityFields = idArray.map(id =&gt; `repeating_${section}_${id}_${quantity}`); const unitFields = multiplier ? idArray.map(id =&gt; `repeating_${section}_${id}_${units}`) : []; getAttrs(quantityFields.concat(unitFields), (v) =&gt; { console.log("=====v alues of v: "+ JSON.stringify(v) +"====="); let sumTotal = 0; const rowValues = quantityFields.map(attr =&gt; parseFloat(v[attr], 10) || 0); if(multiplier) { const rowMultiples = unitFields.map(attr =&gt; parseFloat(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); } sumTotal = sumTotal * multiplytotal; if (round == 'ceil') { sumTotal = Math.ceil(sumTotal); } if (round == 'floor') { sumTotal = Math.floor(sumTotal); } if (round == 'round') { sumTotal = Math.round(sumTotal); } setAttrs({[destination]: sumTotal });&nbsp; &nbsp;&nbsp; }); }); } btw. this doesn't pick up on hidden fields in the fieldset, does it? Whenever I try to do it, the console log shows me an empty value for v. So I thought maybe hidden fields can't go in the fieldset but a quick Google search didn't tell me anything in that direction.
1546106395
GiGs
Pro
Sheet Author
API Scripter
I'm not aware of a reason hidden fields wouldnt be picked up, but I havent tested it with this specific script.&nbsp; What do your hidden inputs look like, and what is the sheet worker? Regarding the rounding tweak, for neatness I would do that as if (round == 'ceil') { sumTotal = Math.ceil(sumTotal); } else if (round == 'floor') { sumTotal = Math.floor(sumTotal); } else if (round == 'round') { sumTotal = Math.round(sumTotal); }
I guess, it is a matter of style. I prefer the simple guard version, as I have learned too complex if/else statements will get me into trouble sometimes. Anyway, the hidden field is nothing out of the ordinary and the change is also pretty standard. ... and just by typing this the solution dawned on my. I didn't use attr_ in the input name. ..testing...yes, it works now. You know, a friend of mine worked in tech support and whenever people dropped by his office he pointed to a teddy bear in the corner and said: "tell it to the teddy bear." In 9 out of 10 cases the solution was obvious and the people realized it themselves. Maybe I should get me a teddy bear&nbsp; for my custom character sheet endeavors.
1546113127
GiGs
Pro
Sheet Author
API Scripter
or a rubber duck! That's commonly used by programmers :)