I am trying to have my sheet update the encumbrance based on the selection of a radio button that chooses a loadout. here is my code thus far // Get Loadout Choice:
on('change:loadoutchoice', function (e) {updateloadout();
});
//Update Loadout
function updateloadout() {
console.log('****updateloadout****');
getAttrs(['loadoutchoice']], function(v) {
var attrs = {};
if (v.loadoutchoice === "a") {
total_weight = "loadouta_total_weight";
}
else if (v.loadoutchoice === "b") {
total_weight = "loadoutb_total_weight";
}
else if (v.loadoutchoice === "c") {
total_weight = "loadoutc_total_weight";
}
setAttrs({
total_weight: total_weight,
});
});
}
// Get Encumbrance Level:
on('change:total_weight change:basic_lift', function (e) {
updateEncLevel();
});
function updateEncLevel(callback) {
getAttrs(['basic_lift', 'total_weight'], function(v) {
callback = callback || noop;
var basicLift = +v.basic_lift;
var encumbranceLevel = Math.floor(v.total_weight / basicLift);
if (encumbranceLevel > 0 && (v.total_weight % basicLift) === 0) {
encumbranceLevel--;
}
if (encumbranceLevel >= 10) {
encumbranceLevel = 5;
} else if (encumbranceLevel >= 6) {
encumbranceLevel = 4;
} else if (encumbranceLevel >= 3) {
encumbranceLevel = 3;
}
setAttrs(
{ encumbrance_level: encumbranceLevel },
{silent: false},
callback
);
});
}