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

Button not working right

Hello So i have a custom sheet for one of my games. i have a button called upkeep. when clicked i am trying to get it so show the resources they gained in the chat and also add the those to the correct resource. but it will not add the resources to the to the stock for that resource on the sheet. im sure it is because of my script. could someone tell me what im doing wrong? below is the script <script type="text/worker"><!-- Upkeep Button--> on('clicked:upkeep', () => { getAttrs(['coin_stock','coin_production'], function(values) { const coin_production = +values.coin_production || 0; const coin_stock = +values.coin_stock || 0; const new_coin_stock = coin_stock + coin_production; setAttrs({coin_stock: new_coin_stock}); startRoll('&{template:default} {{name=@{factionname} Upkeep}} {{Coin=[[@{coin_production}]]}} {{Food=[[@{food_production}]]}} {{Stone=[[@{stone_production}]]}} {{Wood=[[@{wood_production}]]}} {{Metal=[[@{metal_production}]]}} {{Citizen=[[@{citizen_production}]]}} {{Assets=[[@{small_business_qty}d2-@{small_business_qty}]]}}', upkeep => { finishRoll(upkeep.rollId); }); }); </script>
1715611229

Edited 1715612197
GiGs
Pro
Sheet Author
API Scripter
Your code is missing a closure ( a set of }); brackets) which you can see more clearly if you indent ore appropriately, like: on('clicked:upkeep', () => {         getAttrs(['coin_stock','coin_production'], function(values) {              const coin_production = +values.coin_production || 0;              const coin_stock = +values.coin_stock || 0;              const new_coin_stock = coin_stock + coin_production;              setAttrs({coin_stock: new_coin_stock});              startRoll('&{template:default} {{name=@{factionname} Upkeep}} {{Coin=[[@{coin_production}]]}} {{Food=[[@{food_production}]]}} {{Stone=[[@{stone_production}]]}} {{Wood=[[@{wood_production}]]}} {{Metal=[[@{metal_production}]]}} {{Citizen=[[@{citizen_production}]]}} {{Assets=[[@{small_business_qty}d2-@{small_business_qty}]]}}', upkeep => {                    finishRoll(upkeep.rollId);              });  // this closes startRoll         }); // this closes getAttrs }); // this closes the event line, the line that starts On( Try it and see how much of your code it fixes. At present some of your code isn't being run.
So gave that a shot and it still did not work. It now rolls it in the chat, but it is still not adding it to the coin stock. still not sure why it is not working? See image Below <script type="text/worker"><!-- Upkeep Button--> on('clicked:upkeep', () => { getAttrs(['coin_stock','coin_production'], function(values) { const coin_production = +values.coin_production || 0; const coin_stock = +values.coin_stock || 0; const new_coin_stock = coin_stock + coin_production; setAttrs({coin_stock: new_coin_stock}); startRoll('&{template:default} {{name=@{factionname} Upkeep}} {{Coin=[[@{coin_production}]]}} {{Food=[[@{food_production}]]}} {{Stone=[[@{stone_production}]]}} {{Wood=[[@{wood_production}]]}} {{Metal=[[@{metal_production}]]}} {{Citizen=[[@{citizen_production}]]}} ', upkeep => { finishRoll(upkeep.rollId); }); // this closes startRoll }); // this closes getAttrs }); // this closes the event line, the line that starts On( </script>
1715612085
GiGs
Pro
Sheet Author
API Scripter
Also, you can rewrite your code so that the setAttrs and startRoll are dependent on each other and one only runs if the other does. Right now, if there's an error in either of them the other might still run.
1715612134
GiGs
Pro
Sheet Author
API Scripter
Is that a repeating section?
what do you mean repeating section?
1715619970
GiGs
Pro
Sheet Author
API Scripter
If you don't recognise the term, the answer is probably no. A repeating section like like <fieldset class="repating_something"> <1-- lost of code here --> </fieldset> I asked because it was set out like it could be one, and repeating sections use different attribute names, so the code used would be invalid. If that's not the case, though, I can look it at again.
i would appreciate it. im teaching myself so there are thing i dont know and i dont know what they are called. 
1715630191
GiGs
Pro
Sheet Author
API Scripter
Can yiou podst the HTML for that section so I can easily reproduce and test it?
this should be what you need. it is alot <script type="text/worker"><!-- Upkeep Button--> on('clicked:upkeep', () => { startRoll('&{template:default} {{name=@{factionname} Upkeep}} {{Coin=[[@{coin_production}]]}} {{Food=[[@{food_production}]]}} {{Stone=[[@{stone_production}]]}} {{Wood=[[@{wood_production}]]}} {{Metal=[[@{metal_production}]]}} {{Citizen=[[@{citizen_production}]]}} {{Assets=[[@{small_business_qty}d2-@{small_business_qty}]]}}', upkeep => { finishRoll(upkeep.rollId); }); }); </script> </div> <h3>Resource Use</h3> <div class="line2a"><!-- Header --> <h4>&nbsp </h4> <h4>&nbsp </h4> <h6>Production</h6> <h6>Use</h6> <h4>&nbsp </h4> <h4>&nbsp </h4> <h4>&nbsp </h4> <h4>&nbsp </h4> <h6>Assets Maintenance</h6> </div> <div class="line2b"><!-- Header --> <h6>Stock</h6> <h6>Resource</h6> <h6>Per Turn</h6> <h6>Per Turn</h6> <h6>Import</h6> <h6>Export</h6> <h6>Penalty</h6> <h4>&nbsp </h4> <h6>Force</h6> <h6>Cunning</h6> <h6>Wealth</h6> </div> <div class="line2b"><!-- Coin--> <input name="attr_coin_stock" class="text060" type="text" value="0"> <button name="act_coin" class="button3" type="action">Coin</button> <input name="attr_coin_production" class="text070" type="text" value="((@{coin_from_assets})+(@{coin_from_citizen})+(@{coin_from_stats})+(@{coin_from_gold})+(@{coin_from_import}))-((@{coin_penalty})+(@{asset_coin_maintenance})+(@{coin_from_export}))" disabled> <input name="attr_coin_maintenance" class="text070" type="text" value="(@{asset_coin_maintenance})" disabled> <input name="attr_coin_import" class="text070" type="text" value="(@{coin_from_import})" disabled> <input name="attr_coin_export" class="text070" type="text" value="(@{coin_from_export})" disabled> <input name="attr_coin_penalty" class="text070" type="text" value="0"> <h4>&nbsp </h4> <input name="attr_coin_force" class="text060" type="text" value="(@{force_coin_maintenance})" disabled> <input name="attr_coin_cunning" class="text060" type="text" value="(@{cunning_coin_maintenance})" disabled> <input name="attr_coin_wealth" class="text060" type="text" value="(@{wealth_coin_maintenance})" disabled> <div><!-- Hidden inputs used to generate coin Production --> <input name="attr_coin_from_citizen" type="hidden" value="floor((@{citizen_production})/5)" disabled> <input name="attr_coin_from_stats" type="hidden" value="(floor((@{force}+@{cunning})/2))+(ceil((@{wealth})/2))" disabled> <input name="attr_coin_from_gold" type="hidden" value="(@{gold_production})*3" disabled> <input name="attr_coin_from_assets" type="hidden" value="(@{harbor_qty})*2" disabled> <input name="attr_coin_from_export" type="hidden" value="(@{faction_15_coin_export}+@{faction_14_coin_export}+@{faction_13_coin_export}+@{faction_12_coin_export}+@{faction_11_coin_export}+@{faction_10_coin_export}+@{faction_09_coin_export}+@{faction_08_coin_export}+@{faction_07_coin_export}+@{faction_06_coin_export}+@{faction_05_coin_export}+@{faction_04_coin_export}+@{faction_03_coin_export}+@{faction_02_coin_export}+@{faction_01_coin_export}+@{merchant_coin_export})" disabled> <input name="attr_coin_from_import" type="hidden" value="(@{faction_15_coin_import}+@{faction_14_coin_import}+@{faction_13_coin_import}+@{faction_12_coin_import}+@{faction_11_coin_import}+@{faction_10_coin_import}+@{faction_09_coin_import}+@{faction_08_coin_import}+@{faction_07_coin_import}+@{faction_06_coin_import}+@{faction_05_coin_import}+@{faction_04_coin_import}+@{faction_03_coin_import}+@{faction_02_coin_import}+@{faction_01_coin_import}+@{merchant_coin_import})" disabled> </div> </div> <div class="line2b"><!-- Food--> <input name="attr_food_stock" class="text060" type="text" value="0"> <button name="act_food" class="button3" type="action">Food</button> <input name="attr_food_production" class="text070" type="text" value="((@{food_from_base})+(@{food_from_farm})+(@{food_from_import}))-((@{food_penalty})+(@{asset_food_maintenance})+(@{food_from_export}))" disabled> <input name="attr_food_maintenance" class="text070" type="text" value="(@{asset_food_maintenance})" disabled> <input name="attr_food_import" class="text070" type="text" value="(@{food_from_import})" disabled> <input name="attr_food_export" class="text070" type="text" value="(@{food_from_export})" disabled> <input name="attr_food_penalty" class="text070" type="text" value="0"> <h4>&nbsp </h4> <input name="attr_food_force" class="text060" type="text" value="(@{force_food_maintenance})" disabled> <input name="attr_food_cunning" class="text060" type="text" value="(@{cunning_food_maintenance})" disabled> <input name="attr_food_wealth" class="text060" type="text" value="(@{wealth_food_maintenance})" disabled> <div><!-- Hidden inputs used to generate food Production --> <input name="attr_food_from_base" type="hidden" value="(@{base_food}*(@{base_4}+@{base_3}+@{base_2}+@{base_1}))"> <input name="attr_food_from_farm" type="hidden" value="(@{farm_1_qty} *2)"> <input name="attr_food_from_export" type="hidden" value="(@{faction_15_food_export}+@{faction_14_food_export}+@{faction_13_food_export}+@{faction_12_food_export}+@{faction_11_food_export}+@{faction_10_food_export}+@{faction_09_food_export}+@{faction_08_food_export}+@{faction_07_food_export}+@{faction_06_food_export}+@{faction_05_food_export}+@{faction_04_food_export}+@{faction_03_food_export}+@{faction_02_food_export}+@{faction_01_food_export}+@{merchant_food_export})" disabled> <input name="attr_food_from_import" type="hidden" value="(@{faction_15_food_import}+@{faction_14_food_import}+@{faction_13_food_import}+@{faction_12_food_import}+@{faction_11_food_import}+@{faction_10_food_import}+@{faction_09_food_import}+@{faction_08_food_import}+@{faction_07_food_import}+@{faction_06_food_import}+@{faction_05_food_import}+@{faction_04_food_import}+@{faction_03_food_import}+@{faction_02_food_import}+@{faction_01_food_import}+@{merchant_food_import})" disabled> </div> </div> <div class="line2b"><!-- Stone--> <input name="attr_stone_stock" class="text060" type="text" value="0"> <button name="act_stone" class="button3" type="action">Stone</button> <input name="attr_stone_production" class="text070" type="text" value="((@{stone_from_base})+(@{stone_from_quarry})+(@{stone_import}))-((@{stone_export})+(@{stone_penalty}))" disabled> <input name="attr_stone_maintenance" class="text070" type="text" value="0" disabled> <input name="attr_stone_import" class="text070" type="text" value="(@{stone_from_import})" disabled> <input name="attr_stone_export" class="text070" type="text" value="(@{stone_from_export})" disabled> <input name="attr_stone_penalty" class="text070" type="text" value="0"> <h4>&nbsp </h4> <h4>&nbsp </h4> <h4>&nbsp </h4> <h4>&nbsp </h4> <div><!-- Hidden inputs used to generate stone production --> <input name="attr_stone_from_base" type="hidden" value="(@{base_stone}*(@{base_4}+@{base_3}+@{base_2}+@{base_1}))"> <input name="attr_stone_from_quarry" type="hidden" value="(@{quarry_1_qty} *2)"> <input name="attr_stone_from_export" type="hidden" value="(@{faction_15_stone_export}+@{faction_14_stone_export}+@{faction_13_stone_export}+@{faction_12_stone_export}+@{faction_11_stone_export}+@{faction_10_stone_export}+@{faction_09_stone_export}+@{faction_08_stone_export}+@{faction_07_stone_export}+@{faction_06_stone_export}+@{faction_05_stone_export}+@{faction_04_stone_export}+@{faction_03_stone_export}+@{faction_02_stone_export}+@{faction_01_stone_export}+@{merchant_stone_export})" disabled> <input name="attr_stone_from_import" type="hidden" value="(@{faction_15_stone_import}+@{faction_14_stone_import}+@{faction_13_stone_import}+@{faction_12_stone_import}+@{faction_11_stone_import}+@{faction_10_stone_import}+@{faction_09_stone_import}+@{faction_08_stone_import}+@{faction_07_stone_import}+@{faction_06_stone_import}+@{faction_05_stone_import}+@{faction_04_stone_import}+@{faction_03_stone_import}+@{faction_02_stone_import}+@{faction_01_stone_import}+@{merchant_stone_import})" disabled> </div> </div> <div class="line2b"><!-- Wood--> <input name="attr_wood_stock" class="text060" type="text" value="0"> <button name="act_wood" class="button3" type="action">Wood</button> <input name="attr_wood_production" class="text070" type="text" value="((@{wood_from_base})+(@{wood_from_mill})+(@{wood_import}))-((@{wood_export})+(@{wood_penalty}))" disabled> <input name="attr_wood_maintenance" class="text070" type="text" value="0" disabled> <input name="attr_wood_import" class="text070" type="text" value="(@{wood_from_import})" disabled> <input name="attr_wood_export" class="text070" type="text" value="(@{wood_from_export})" disabled> <input name="attr_wood_penalty" class="text070" type="text" value="0"> <h4>&nbsp </h4> <h4>&nbsp </h4> <h4>&nbsp </h4> <h4>&nbsp </h4> <div><!-- Hidden inputs used to generate wood production --> <input name="attr_wood_from_base" type="hidden" value="(@{base_wood}*(@{base_4}+@{base_3}+@{base_2}+@{base_1}))"> <input name="attr_wood_from_mill" type="hidden" value="(@{mill_1_qty} *2)"> <input name="attr_wood_from_export" type="hidden" value="(@{faction_15_wood_export}+@{faction_14_wood_export}+@{faction_13_wood_export}+@{faction_12_wood_export}+@{faction_11_wood_export}+@{faction_10_wood_export}+@{faction_09_wood_export}+@{faction_08_wood_export}+@{faction_07_wood_export}+@{faction_06_wood_export}+@{faction_05_wood_export}+@{faction_04_wood_export}+@{faction_03_wood_export}+@{faction_02_wood_export}+@{faction_01_wood_export}+@{merchant_wood_export})" disabled> <input name="attr_wood_from_import" type="hidden" value="(@{faction_15_wood_import}+@{faction_14_wood_import}+@{faction_13_wood_import}+@{faction_12_wood_import}+@{faction_11_wood_import}+@{faction_10_wood_import}+@{faction_09_wood_import}+@{faction_08_wood_import}+@{faction_07_wood_import}+@{faction_06_wood_import}+@{faction_05_wood_import}+@{faction_04_wood_import}+@{faction_03_wood_import}+@{faction_02_wood_import}+@{faction_01_wood_import}+@{merchant_wood_import})" disabled> </div> </div> <div class="line2b"><!-- Metal--> <input name="attr_metal_stock" class="text060" type="text" value="0"> <button name="act_metal" class="button3" type="action">Metal</button> <input name="attr_metal_production" class="text070" type="text" value="((@{metal_from_base})+(@{metal_from_metal_mine})+(@{metal_import}))-((@{metal_export})+(@{metal_penalty}))" disabled> <input name="attr_metal_maintenance" class="text070" type="text" value="0" disabled> <input name="attr_metal_import" class="text070" type="text" value="(@{metal_from_import})" disabled> <input name="attr_metal_export" class="text070" type="text" value="(@{metal_from_export})" disabled> <input name="attr_metal_penalty" class="text070" type="text" value="0"> <h4>&nbsp </h4> <h4>&nbsp </h4> <h4>&nbsp </h4> <h4>&nbsp </h4> <div><!-- Hidden inputs used to generate meteal production --> <input name="attr_metal_from_base" type="hidden" value="(@{base_metal}*(@{base_4}+@{base_3}+@{base_2}+@{base_1}))"> <input name="attr_metal_from_metal_mine" type="hidden" value="(@{metal_mine_1_qty} *2)"> <input name="attr_metal_from_export" type="hidden" value="(@{faction_15_metal_export}+@{faction_14_metal_export}+@{faction_13_metal_export}+@{faction_12_metal_export}+@{faction_11_metal_export}+@{faction_10_metal_export}+@{faction_09_metal_export}+@{faction_08_metal_export}+@{faction_07_metal_export}+@{faction_06_metal_export}+@{faction_05_metal_export}+@{faction_04_metal_export}+@{faction_03_metal_export}+@{faction_02_metal_export}+@{faction_01_metal_export}+@{merchant_metal_export})" disabled> <input name="attr_metal_from_import" type="hidden" value="(@{faction_15_metal_import}+@{faction_14_metal_import}+@{faction_13_metal_import}+@{faction_12_metal_import}+@{faction_11_metal_import}+@{faction_10_metal_import}+@{faction_09_metal_import}+@{faction_08_metal_import}+@{faction_07_metal_import}+@{faction_06_metal_import}+@{faction_05_metal_import}+@{faction_04_metal_import}+@{faction_03_metal_import}+@{faction_02_metal_import}+@{faction_01_metal_import}+@{merchant_metal_import})" disabled> </div> </div> <div class="line2b"><!-- Citizen--> <input name="attr_citizen_stock" class="text060" type="text" value="((@{citizen_production})+(@{citizen_import}))-((@{citizen_maintenance})+(@{citizen_export})+(@{citizen_penalty}))" disabled> <button name="act_citizen" class="button3" type="action">Citizen</button> <input name="attr_citizen_production" class="text070" type="text" value="(@{citizen_from_base})" disabled> <input name="attr_citizen_maintenance" class="text070" type="text" value="(@{asset_citizen_maintenance})" disabled> <input name="attr_citizen_import" class="text070" type="text" value="(@{citizen_from_import})" disabled> <input name="attr_citizen_export" class="text070" type="text" value="(@{citizen_from_export})" disabled> <input name="attr_citizen_penalty" class="text070" type="text" value="0"> <h4>&nbsp </h4> <input name="attr_citizen_force" class="text060" type="text" value="(@{force_citizen_maintenance})" disabled> <input name="attr_citizen_cunning" class="text060" type="text" value="(@{cunning_citizen_maintenance})" disabled> <input name="attr_citizen_wealth" class="text060" type="text" value="(@{wealth_citizen_maintenance})" disabled> <div><!-- Hidden inputs used to generate citizen production --> <input name="attr_citizen_from_base" type="hidden" value="((@{base_4_citizin})*(@{base_4}))+((@{base_3_citizin})*(@{base_3}))+((@{base_2_citizin})*(@{base_2}))+((@{base_1_citizin})*(@{base_1}))"> <input name="attr_citizen_from_export" type="hidden" value="(@{faction_15_citizen_export}+@{faction_14_citizen_export}+@{faction_13_citizen_export}+@{faction_12_citizen_export}+@{faction_11_citizen_export}+@{faction_10_citizen_export}+@{faction_09_citizen_export}+@{faction_08_citizen_export}+@{faction_07_citizen_export}+@{faction_06_citizen_export}+@{faction_05_citizen_export}+@{faction_04_citizen_export}+@{faction_03_citizen_export}+@{faction_02_citizen_export}+@{faction_01_citizen_export}+@{merchant_citizen_export})" disabled> <input name="attr_citizen_from_import" type="hidden" value="(@{faction_15_citizen_import}+@{faction_14_citizen_import}+@{faction_13_citizen_import}+@{faction_12_citizen_import}+@{faction_11_citizen_import}+@{faction_10_citizen_import}+@{faction_09_citizen_import}+@{faction_08_citizen_import}+@{faction_07_citizen_import}+@{faction_06_citizen_import}+@{faction_05_citizen_import}+@{faction_04_citizen_import}+@{faction_03_citizen_import}+@{faction_02_citizen_import}+@{faction_01_citizen_import}+@{merchant_citizen_import})" disabled> </div> </div> <div class="line2b"><!-- Gold--> <input name="attr_gold_stock" class="text060" type="text" value="0"> <button name="act_gold" class="button3" type="action">Gold</button> <input name="attr_gold_production" class="text070" type="text" value="((@{gold_from_gold_mine})+(@{gold_import}))-((@{gold_export})+(@{gold_penalty}))" disabled> <input name="attr_gold_maintenance" class="text070" type="text" value="0" disabled> <input name="attr_gold_import" class="text070" type="text" value="(@{gold_from_import})" disabled> <input name="attr_gold_export" class="text070" type="text" value="(@{gold_from_export})" disabled> <input name="attr_gold_penalty" class="text070" type="text" value="0"> <h4>&nbsp </h4> <h4>&nbsp </h4> <h4>&nbsp </h4> <h4>&nbsp </h4> <div><!-- Hidden inputs used to generate meteal production --> <input name="attr_gold_from_gold_mine" type="hidden" value="(@{gold_mine_1_qty})"> <input name="attr_gold_from_export" type="hidden" value="(@{faction_15_gold_export}+@{faction_14_gold_export}+@{faction_13_gold_export}+@{faction_12_gold_export}+@{faction_11_gold_export}+@{faction_10_gold_export}+@{faction_09_gold_export}+@{faction_08_gold_export}+@{faction_07_gold_export}+@{faction_06_gold_export}+@{faction_05_gold_export}+@{faction_04_gold_export}+@{faction_03_gold_export}+@{faction_02_gold_export}+@{faction_01_gold_export}+@{merchant_gold_export})" disabled> <input name="attr_gold_from_import" type="hidden" value="(@{faction_15_gold_import}+@{faction_14_gold_import}+@{faction_13_gold_import}+@{faction_12_gold_import}+@{faction_11_gold_import}+@{faction_10_gold_import}+@{faction_09_gold_import}+@{faction_08_gold_import}+@{faction_07_gold_import}+@{faction_06_gold_import}+@{faction_05_gold_import}+@{faction_04_gold_import}+@{faction_03_gold_import}+@{faction_02_gold_import}+@{faction_01_gold_import}+@{merchant_gold_import})" disabled> </div> </div>
1715631685

Edited 1715641442
GiGs
Pro
Sheet Author
API Scripter
Before I test it, I see one problem. attr_coin_production appears to be an autocalc field (a disabled input, used to calculate a number). Sheet workers cannot read the contents of disabled inputs properly. So this line const coin_production = +values.coin_production || 0; will always equal 0. Your setAttrs command may be working, but no change ever occurs because that variable is always zero. This can be seen as a problem with sheet workers, but it's really an incompatibility between sheet workers and autocalc fields. Once you start using sheet workers a lot, you inevitably end up replacing all the autocalc attributes in your sheet with sheet workers. (This is good: they are better in every way except the ease of creating them.)
1715648571

Edited 1715649083
GiGs
Pro
Sheet Author
API Scripter
I cant test the above code, because it has autocalcs that require attributes from elsewhetre in the sheet, but since it looks like the vast majority of them are either single attributes or grups of attributes you just add together, they could be replaced with some short sheet worker code. First, I would do a global find/replace and change disabled to readonly . Next, build an object in notepad that looks like this: const inputs = {     gold_from_gold_mine: [ 'gold_mine_1_qty' ],     gold_from_import: [ 'faction_15_gold_import' , 'faction_14_gold_import' , 'faction_13_gold_import' , 'faction_12_gold_import' , 'faction_11_gold_import' , 'faction_10_gold_import' , 'faction_09_gold_import' , 'faction_08_gold_import' , 'faction_07_gold_import' , 'faction_06_gold_import' , 'faction_05_gold_import' , 'faction_04_gold_import' , 'faction_03_gold_import' , 'faction_02_gold_import' , 'faction_01_gold_import' , 'merchant_gold_import' ],     /* input name: [all attributes to be added put in an array, each attribute in quotes and separated by a comma ] */ } What your doing here: going through every single autoclac which is either a single attribute or a group of attributes added together: at the start of the line, the name of the input (with the attr_ part removed) The a placeholder for an array of attributes that looks like : ['']; Inside that paste the autocalc attributes that might be like @{something}+@{something_else}, so you'll have a line that looks like this: destination: ['@{something}+@{something_else}']; Once you have created all the lines, do several global find/replaces: find: }+@{ replace: ', ' find: ['@{ replace: [' find: }'] replace: '] you'll now have several lines that look like destination: ['something', 'something_else']; Now copy that into the inputs variable, see what I have for refetrence. Finally, copy this into your script block (replacing this const inputs with the one you just created). const inputs = {     gold_from_gold_mine: [ 'gold_mine_1_qty' ],     gold_from_import: [ 'faction_15_gold_import' , 'faction_14_gold_import' , 'faction_13_gold_import' , 'faction_12_gold_import' , 'faction_11_gold_import' , 'faction_10_gold_import' , 'faction_09_gold_import' , 'faction_08_gold_import' , 'faction_07_gold_import' , 'faction_06_gold_import' , 'faction_05_gold_import' , 'faction_04_gold_import' , 'faction_03_gold_import' , 'faction_02_gold_import' , 'faction_01_gold_import' , 'merchant_gold_import' ],     /* input name: [all attributes to be added put in an array, each attribute in quotes and separated by a comma ] */ } Object . keys ( inputs ). forEach ( input => {     const atts = inputs [ input ];     on ( ` ${ atts . map ( att => `change: ${ att } ` ). join ( ' ' ) } sheet:opened` , () => {         getAttrs ( atts , values => {             const output = {};             const sum = atts . reduce (( all , one ) => all + (+ values [ one ] || 0 ), 0 );             setAttrs ({                 [input]: sum             });         });     }); }); This code will create a sheet worker for each autocalc from the inputs object. Any that use floor() or divide by 2 or 5 or anything that is not a plain addition can't be handled by this. For now, in the html replace them with value="0" (you can create proper sheet workers for the later), and we can get them working properly later once we know these are working. And that's it - a massive number of your autocalcs have been converted to sheet workers, and that sheet worker from above should work properly. Note you have some that a multiples, like: value="(@{harbor_qty})*2" You can do these by just adding the attribute as many times as the multiple, like: : [ ' harbor_qty ' , ' harbor_qty '],