Hi all! I have a number of traits I want to sum some values for and I'm trying to dynamically create their "change:traitN" events on startup, iterating over a loop of the trait names and how many child fields the change event needs to cover. The issue is only the final on(change) event seems to be sticking around. var allTotals = { 'hack':4, 'hunt':4, 'read':4, 'scrounge':4, 'stress':9 };
// when sheet's opened, create on change events for all fields in allTotals
var init = function() {
for (f in allTotals) {
var numFields = allTotals[f];
var changeStr = "";
for(i = 1; i <= numFields; i++) {
changeStr = changeStr + "change:" + f + i + " ";
}
on(changeStr, function(eventInfo) {
console.log('INIT():',eventInfo);
setTotal(f, numFields);
});
console.log('INIT():', changeStr, f, numFields);
}
}
In this case, changing Hunt or Scrounge or what have you only triggers the event for Stress.