Here are my edits, most of them are just simplifying some of your coding using the underscore.js library that is included with Roll20; there was only one substantive change made. <script type="text/worker">
on("change:repeating_inventory:item_weight change:repeating_inventory:item_carrying change:repeating_inventory:item_quantity remove:repeating_inventory", function() {
getSectionIDs("repeating_inventory", function(IDArray) {
var fieldNames = [];
_.each(IDArray,(id)=>{//Underscore.js is a very useful library for doing many things that used to require ugly expressions, like for loops
fieldNames.push("repeating_inventory_" + id + "_item_weight");
fieldNames.push("repeating_inventory_" + id + "_item_quantity");
fieldNames.push("repeating_inventory_" + id + "_item_carrying");
});
var total = 0;
var per = 0;
var equipped = 0;
getAttrs(fieldNames, function(values) {
_.each(IDArray,(id)=>{
equipped = values["repeating_inventory_" + id + "_item_carrying"]*1;//This is the only change that I think you actually needed for this to work. Attributes are text (aka strings) by default, so your checkbox was actually evaluating to "0" or "1", both of which are truthy in javascript. Multiplying by 1 converts it to a number (or NaN if it can't be converted) allowing your if statement to work.
if (equipped){//this should now properly gate whether or not to add the weight of the item
per = values["repeating_inventory_" + id + "_item_weight"]*1||0;
total+= per*values["repeating_inventory_" + id + "_item_quantity"]||0;
}
});
setAttrs({weight_total: total});
});
});
});
</script> Hope that helps. EDIT: To post use the code formatting, select it from the paragraph symbol dropdown menu in the top left of the post textarea.