
I'm having some trouble with updating a readonly field within a repeating section called "weapons" that displays the sum of the player's total base attack bonus (BAB), size modifier, and, depending on the selection of the attack modifier select field (it can be STR, CON, DEX, INT, WIS, or CHA), adds that associated amount to the sum as well. The problem lies in that, when executing the code below, it seems to routinely run out of bounds with the for loop. An example of this would be having an idarr (amount of rows) length of 2, and the function attempts to mistakenly instantiate idarr[2], leading to an undefined amount, thus not updating the amount since it cannot fetch the row ID. Am I overlooking something here? on("change:str-mod change:dex-mod change:con-mod change:int-mod change:wis-mod change:cha-mod change:total-bab change:size-mod-atk", function() { getSectionIDs("repeating_weapons", function (idarr) { for (var i = 0; i < idarr.length; i++) { getAttrs(["repeating_weapons_" + idarr[i] + "_weapon-attack-modifier", "total-bab", "size-mod-atk", "str-mod", "dex-mod", "con-mod", "int-mod", "wis-mod", "cha-mod"], function (values) { var attackModifier = values[Object.keys(values)[0]]; // select field var attackBonus = parseInt(values["total-bab"]) + parseInt(values["size-mod-atk"]); switch (attackModifier) { case "STR": attackBonus += parseInt(values["str-mod"]); break; case "DEX": attackBonus += parseInt(values["dex-mod"]); break; case "CON": attackBonus += parseInt(values["con-mod"]); break; case "INT": attackBonus += parseInt(values["int-mod"]); break; case "WIS": attackBonus += parseInt(values["wis-mod"]); break; case "CHA": attackBonus += parseInt(values["cha-mod"]); break; default: attackBonus = -1; } var attrs = {}; attrs["repeating_weapons_" + idarr[i] + "_weapon-attack-bonus"] = attackBonus; setAttrs(attrs); }); } }); });