Trying to get a total encumberance based on character strength/weight plus total weight of coinage / other items. I have the following setup: input fields used on char sheet
attr_char_str_total (total strength bonus)
attr_character_weight (character weight)
attr_platimun1 attr_gold1 attr_silver1 attr_bronze1 attr_copper1 attr_tin1 attr_iron1 (coinage)
fieldset
repeating_inventory: attr_itemcount (number of inventory item)
repeating_inventory: attr_itemweight (weight of single inventory item)
return field: attr_enc_total I then have the following scripts written: <script type="text/worker">
on("change:char_str_total change:character_weight change:repeating_inventory:itemweight change:repeating_inventory:itemcount change:platimun1 change gold1 change:silver1 change:bronze1 change:copper1 change:tin1 change:iron1 sheet:opened", function() {
update_weight();
});
var update_weight = function() {
var update = {};
var wtotal = 0;
var weightratio = 0;
var enc_penalty = 0;
var final_penalty = 0;
var weight_attrs = ["platimun1","gold1","silver1","bronze1","copper1","tin1","iron1","character_weight","char_str_total"];
getSectionIDs("repeating_inventory", function(idarray) {
_.each(idarray, function(currentID, i) {
weight_attrs.push("repeating_inventory_" + currentID + "_itemweight");
weight_attrs.push("repeating_inventory_" + currentID + "_itemcount");
});
getAttrs(weight_attrs, function(v) {
platimun1 = isNaN(parseInt(v.platimun1, 10)) === false ? parseInt(v.platimun1, 10) : 0;
gold1 = isNaN(parseInt(v.gold1, 10)) === false ? parseInt(v.gold1, 10) : 0;
silver1 = isNaN(parseInt(v.silver1, 10)) === false ? parseInt(v.silver1, 10) : 0;
bronze1 = isNaN(parseInt(v.bronze1, 10)) === false ? parseInt(v.bronze1, 10) : 0;
copper1 = isNaN(parseInt(v.copper1, 10)) === false ? parseInt(v.copper1, 10) : 0;
tin1 = isNaN(parseInt(v.tin1, 10)) === false ? parseInt(v.tin1, 10) : 0;
iron1 = isNaN(parseInt(v.iron1, 10)) === false ? parseInt(v.iron1, 10) : 0;
wtotal = wtotal + ((platimun1 + gold1 + silver1 + bronze1 + copper1 + tin1 + iron1) / 50);
_.each(idarray, function(currentID, i) {
if(v["repeating_inventory_" + currentID + "_itemweight"] && isNaN(parseInt(v["repeating_inventory_" + currentID + "_itemweight"], 10)) === false) {
count = v["repeating_inventory_" + currentID + "_itemcount"] && isNaN(parseFloat(v["repeating_inventory_" + currentID + "_itemcount"])) === false ? parseFloat(v["repeating_inventory_" + currentID + "_itemcount"]) : 1;
wtotal = wtotal + (parseFloat(v["repeating_inventory_" + currentID + "_itemweight"]) * count);
}
});
weightratio = wtotal / v.character_weight;
if (weightratio < 10) {penalty = 0;}
else if (weightratio < 20) {penalty = 10;}
else if (weightratio < 30) {penalty = 20;}
else if (weightratio < 40) {penalty = 30;}
else if (weightratio < 50) {penalty = 40;}
else if (weightratio < 60) {penalty = 50;}
else if (weightratio < 70) {penalty = 60;}
else if (weightratio < 80) {penalty = 70;}
else if (weightratio < 90) {penalty = 80;}
else if (weightratio < 100) {penalty = 90;}
enc_penalty = v.char_str_total - penalty;
if (enc_penalty < 0) {final_penalty = enc_penalty;}
else {final_penalty = 0;}
setAttrs({
enc_total: final_penalty;
});
});
});
};
</script> When I make the changes to the fields listed in the on:change section the enc_total field is not updating. Please can you advise where I have gone wrong?