First I must state I am extremely new to HTML5, Javascript, and CSS coding. PART 1 I am working on a character sheet, I am not the original author, that has the following code to determine if a Language cost has change and to update the totals - all from a Repeating Section. The code works perfectly fine, but now I need to also have it check if new attributes, not part of any Repeating Section, have changed and if so to add their point costs as well into the totals. These new attributes are named: attr_native_language_spoken and attr_native_language_written The code is as follows: // Update the total cost of Languages on('change:repeating_languages:spoken change:repeating_languages:written remove:repeating_languages', function (e) { var total = 0; var tally = _.after(2, function () { setAttrs({ languages_points: total }); }); sumRepeating('repeating_languages', 'spoken', function(v) { console.log('Spoken: ' + v); total += +v; tally(); }); sumRepeating('repeating_languages', 'written', function(v) { console.log('Written: ' + v); total += +v; tally(); }); }); // function to sum a field from a repeating section
function sumRepeating(sectionName, fieldName, callback) {
getSectionIDs(sectionName, function (ids) {
if (ids.length === 0 ) {
callback(0);
return;
}
var fieldArray = [];
for (var i = 0; i < ids.length; i++) {
fieldArray.push(sectionName + '_' + ids[i] + '_' + fieldName);
}
getAttrs(fieldArray, function (fieldValues) {
var vals = Object.values(fieldValues);
vals.push(0);
var total = vals.reduce(getSum);
callback(total);
});
});
}
How would I go about making the changes I need? Note after it detects that costs have changed, there is additional code: // Update Summery on('change:tl_pts change:appearance change:languages_points change:cf_points change:advantages_points change:disadvantages_points change:racial_points', function (e) { getAttrs(['tl_pts', 'appearance', 'languages_points', 'cf_points', 'advantages_points', 'disadvantages_points', 'racial_points'], function(v) { var vals = Object.values(v); vals.push(0); setAttrs({ trait_points: vals.reduce(getSum) }); }); }); Does this code need t be modified as well in any way? Any help at all would be greatly appreciated.