Right, so this is nearly working how I want it. It successfully populates the repeating section and equips the weapon (by "clicking" the equip button) on actiation. On deactivation, it successfully removes the Vorpal Blade entry. However, it does not equip the weapon in the first row after removing the Vorpal Blade. I'd actually prefer it to equip the 'last used' weapon, but I have not successfully managed that either. I have been successful in generating an empty new row and equipping that to clear the Vorpal Blade stats, but then I'm left with a bunch of empty rows after casting the spell a few times. on("change:vorpal_blade", function() { getAttrs(["vorpal_blade"], function(values) { const vorpalBladeStatus = parseInt(values.vorpal_blade) || 0; // When Vorpal Blade is set to "Active" (1) if (vorpalBladeStatus === 1) { getSectionIDs("repeating_meleeweapons", function(ids) { let foundVorpalBlade = false; // Iterate over the rows to check if the Vorpal Blade is already present ids.forEach(function(id) { getAttrs([`repeating_meleeweapons_${id}_meleeweaponname`], function(weaponValues) { const weaponName = weaponValues[`repeating_meleeweapons_${id}_meleeweaponname`] || ""; if (weaponName === "Vorpal Blade") { foundVorpalBlade = true; setAttrs({ [`clicked:repeating_meleeweapons_${id}_equippedmeleewep`]: 1 }); } }); }); // If not found, create the Vorpal Blade entry if (!foundVorpalBlade) { const newRowId = generateRowID(); const newWeaponAttrs = {}; newWeaponAttrs[`repeating_meleeweapons_${newRowId}_meleeweaponname`] = 'Vorpal Blade'; newWeaponAttrs[`repeating_meleeweapons_${newRowId}_meleeweapon`] = 'Sword'; newWeaponAttrs[`repeating_meleeweapons_${newRowId}_magicmeleeweaponbonus`] = 3; newWeaponAttrs[`repeating_meleeweapons_${newRowId}_meleeabr`] = 'd8'; newWeaponAttrs[`repeating_meleeweapons_${newRowId}_meleedamage`] = '4'; newWeaponAttrs[`repeating_meleeweapons_${newRowId}_meleeothereffects`] = 'In the caster’s hand there appears a magic sword— as black as midnight, with a coruscating nimbus of green fire.'; setAttrs(newWeaponAttrs, function() { setAttrs({ [`clicked:repeating_meleeweapons_${newRowId}_equippedmeleewep`]: 1 }); }); } }); // When Vorpal Blade is set to "Inactive" (0) } else { getSectionIDs("repeating_meleeweapons", function(ids) { let foundVorpalBlade = false; // Iterate over the rows to check for the Vorpal Blade entry ids.forEach(function(id) { getAttrs([`repeating_meleeweapons_${id}_meleeweaponname`], function(weaponValues) { const weaponName = weaponValues[`repeating_meleeweapons_${id}_meleeweaponname`] || ""; // If Vorpal Blade is found, remove it if (weaponName === "Vorpal Blade") { removeRepeatingRow(`repeating_meleeweapons_${id}`); } }); }); // Equip the first available row after removal if (ids.length > 0) { setAttrs({ [`clicked:repeating_meleeweapons_${ids[0]}_equippedmeleewep`]: 1 }); } }); } }); });