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 problem

1706029962
Maïlare
Pro
Sheet Author
API Scripter
Hello, I have a problem with a repeatingSum function. I have code it same as usual but it's not functionnal. Here the code. The code with the total value : < div class = "charsheet-size" > <!--Beginning of character sheet-->     <!--Beginning of character description-->     < div id = "character_description" >         < div class = 'sheet-2colrow' >             <!--Left column-->             ...             <!--Right column-->             < div class = "sheet-col" style = " margin-left: 0px; width: 573px;" >                 < input type = "text" class = "cell-name-2col" value = "Character Backstory" />                 < input type = "text" class = "cell-content-2col" name = "attr_CharacterBackstory" />< br >                 < input type = "text" class = "cell-name-2col" value = "Character Personality" />                 < input type = "text" class = "cell-content-2col" name = "attr_CharacterPersonality" />< br >                 < input type = "text" class = "cell-name-2col" value = "Character Appearance" />                 < input type = "text" class = "cell-content-2col" name = "attr_CharacterAppearance" />< br >                 < input type = "text" class = "cell-name-2col" value = "Current Level" />                 <!--Total value--> < input type = "number" class = "cell-content-2col" name = "attr_CurrentLvl" readonly = "readonly" />< br >                 < input type = "text" class = "cell-name-2col" value = "Current Maximum Power" />                 < input type = "text" class = "cell-content-2col" name = "attr_CurrentMaxPwr" />< br >                 < input type = "text" class = "cell-name-2col" value = "Specific Attempts" />                 < input type = "text" class = "cell-content-2col" name = "attr_SpecAttempts" />             </ div >         </ div > The code of the repeating section : < fieldset class = "repeating_characteristic" >      < div class = "dark-row" style = " margin-bottom: 2px;" >          < div class = 'sheet-2colrow' >               <!--Left column-->               < div class = "sheet-col" style = " background-color: #B6D7A8; width: 650px; margin-right: 0px;" >                   < input class = "textbox" type = "text" name = "attr_CharacteristicName" value = "Name" style = " margin-left: 10px;" />                   < button type = "roll" title = "PowerRoll" name = "roll_CharacteristicPower" style = " margin-left: 15px;" value = "&{template:default} {{name=@{CharacteristicName } }} {{Power=[[1d@{CharacteristicPower}]]}}" ></ button >                   < input class = "textbox" type = "number" name = "attr_CharacteristicPower" value = "0" />                   < button type = "roll" title = "ControlRoll" name = "roll_CharacteristicProficiency" style = " margin-left: 10px;" value = "&{template:default} {{name=@{CharacteristicName } }} {{Proficiency=[[1d@{CharacteristicProficiency}]]}}" ></ button >                   < input class = "textbox" type = "number" name = "attr_CharacteristicProficiency" value = "0" style = " margin-left: 0px;" />                   < button type = "roll" title = "ControlRoll" name = "roll_CharacteristicControl" style = " margin-left: 5px;" value = "&{template:default} {{name=@{CharacteristicName } }} {{Control=[[1d@{CharacteristicControl}]]}}" ></ button >                   < input class = "textbox" type = "number" name = "attr_CharacteristicControl" value = "0" />                   < input class = "textbox" type = "number" name = "attr_CharacteristicMass" value = "0" style = " margin-left: 2px;" />                   < input class = "textbox" type = "number" name = "attr_CharacteristicLength" value = "0" />                   < input class = "textbox" type = "number" name = "attr_CharacteristicWidth" value = "0" style = " margin-left: 2px;" />                   <!--Total of values in the repeating section--> < input class = "textbox" type = "number" name = "attr_CharacteristicLevel" value = "(@{CharacteristicPower}+@{CharacteristicProficiency}+@{CharacteristicControl}+@{CharacteristicMass}+@{CharacteristicLength}+@{CharacteristicWidth})" disabled = "disabled" />              </ div >              <!--Right column-->              < div class = "sheet-col" style = " background-color: #FFE599; width: 492px; margin-left: 0px;" >                  < input class = "textbox" type = "number" name = "attr_CharacteristicQuantity" value = "0" style = " margin-left: 9px;" />                  < input class = "textbox" type = "number" name = "attr_CharacteristicDamage" value = "0" style = " margin-left: 17px;" />                  < input class = "textbox" type = "number" name = "attr_CharacteristicComplexity" value = "0" style = " margin-left: 25px;" />                  < input class = "textbox" type = "text" name = "attr_CharacteristicPosition" value = "Position" style = " width: 105px; margin-left: 15px;" />                  < input class = "textbox" type = "text" name = "attr_CharacteristicDescription" value = "Description" />              </ div >          </ div >      </ div > </ fieldset > The code of the repeatingSum script : < script type = "text/worker" >     /* ===== PARAMETERS ==========     destinations = the name of the attribute that stores the total quantity         can be a single attribute, or an array: ['total_cost', 'total_weight']         If more than one, the matching fields must be in the same order.     section = name of repeating fieldset, without the repeating_     fields = the name of the attribute field to be summed           destination and fields both can be a single attribute: 'weight'           or an array of attributes: ['weight','number','equipped']     */     const repeatingSum = (destinations, section, fields) => {         if (!Array.isArray(destinations)) destinations = [destinations.replace(/\s/g, '').split(',')];         if (!Array.isArray(fields)) fields = [fields.replace(/\s/g, '').split(',')];         getSectionIDs(`repeating_${section}`, idArray => {             const attrArray = idArray.reduce((m, id) => [...m, ...(fields.map(field => `repeating_${section}_${id}_${field}`))], []);             getAttrs([...attrArray], v => {                 const getValue = (section, id, field) => v[`repeating_${section}_${id}_${field}`] === 'on' ? 1 : parseFloat(v[`repeating_${section}_${id}_${field}`]) || 0;                 const commonMultipliers = (fields.length <= destinations.length) ? [] : fields.splice(destinations.length, fields.length - destinations.length);                 const output = {};                 destinations.forEach((destination, index) => {                     output[destination] = idArray.reduce((total, id) => total + getValue(section, id, fields[index]) * commonMultipliers.reduce((subtotal, mult) => subtotal * getValue(section, id, mult), 1), 0);                 });                 setAttrs(output);             });         });     };     //Current level value     on('change:repeating_characteristic remove:repeating_characteristic', function() {         repeatingSum("CurrentLvl","characteristic","CharacteristicLevel");     }); </ script >
1706030363

Edited 1706038124
GiGs
Pro
Sheet Author
API Scripter
I was going to ask "What is the problem? What are expecting to happen, and what is happening instead (which might be nothing)" but I see the issue. Workers (all  workers, this isn't anything special about repeatingSum) cannot work with disabled attributes. Characteristic_Level is a disabled attribute, so cannot work with this (or any) worker. You need to change the attribute to a compatible attribute - which is usually done with sheet workers. OR you could bypass it entirely.
1706030941

Edited 1706031891
Maïlare
Pro
Sheet Author
API Scripter
GiGs said: I was going to ask "What is the problem? What are expecting to happen, and what is happing instead (which might be nothing)" but I see the issue. Workers (all  workers, this isn't anything special about repeatingSum) cannot work with disabled attributes. Characteristic_Level is a disabled attribute, so cannot work with this (or any) worker. You need to change the attribute to a compatible attribute - which is usually done ith sheet workers. OR you could bypass it entirely. Hello and thanks for the answer, but in my others character sheets, it works in the others sheets with disabled attributes.
1706031762

Edited 1706031883
GiGs
Pro
Sheet Author
API Scripter
I'd check the sheets again. Sheet workers cannot work with disabled attributes. This isn't a theory, it's a well-documented fact. If your other sheets seem to work, something else is going on and it would be nice to know what it is.
1706031925
Maïlare
Pro
Sheet Author
API Scripter
GiGs said: I'd check the sheets again. Sheet workers cannot work with disabled attributes. This isn't a theory, it's a well-documented fact. If your other sheets seem to work, something else is going on and it would be nice to know what it is. I have make a sheetworker to calculate this attributes. I have to reorganized the code of the other sheets lol.
1706042383
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Disabled attributes (aka autocalcs) can  work with sheetworkers, it's just that the infrastructure to allow it to happen is a lot of very fiddly code and requires that you write your sheetworkers in such a way that you are getting the values for every attribute you might potentially need in your getAttrs  call. Combined, these usually make it a difficult to impossible task unless you're using a sheet framework like the K-scaffold which already provides all that information (but then you've got better options than using an autocalc attribute).
1706042699

Edited 1706046252
GiGs
Pro
Sheet Author
API Scripter
Correct me if this is mistaken, Scott: It's true that you can get the value from a disabled attribute (but it will be a string, not a number). My understanding though is you can't directly change a disabled attribute: setAttrs won't work on it. (There is a way to fake it, by having another attribute that the setAttrs updates, and your disabled attribute is set to be equal to that attribute.) OP in this thread was trying to use setAttrs to set a disabled attribute, and that won't work.
1706043130
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
ah! yes, I missed that a setAttrs was being attempted on the disabled attribute. You're correct, that won't work.