All right. I swear this sheet worker used to work. I can't see anything that's changed, and characters I've pulled up had the proper values calculated using it, then when I changed a value, it broke and returned a bad value. So something is broken. I've decided to stop worrying about the timeline and just try to fix it. The problem is the values of the "elements" variables, foo_air, foo_earth, etc, which should be added in at 10 x their value. They aren't being added in at all. If I change them it does seem to trigger the worker. They seem to be correct in the variables in the sheet. They just aren't being calculated in the actual equation where they are meant to be added together, multiplied by ten, and then added to the ranks and all the repeating cells. The total value returned is JUST the total of the normal ranks and the repeating cells. Anyway, here's the code, as we created way back when. Tell me if you can help me spot the issue. <!-- Insight Calculation Worker -->
<script type="text/worker">
var elements = ['foo_air', 'foo_earth', 'foo_fire', 'foo_water', 'foo_void'],
ranks = ['rank_acting', 'rank_artisan', 'rank_calligraphy', 'rank_courtier', 'rank_divination', 'rank_etiquette', 'rank_games', 'rank_investigation', 'rank_lore', 'rank_Lore2', 'rank_Lore3', 'rank_Medicine', 'rank_Meditation', 'rank_Perform', 'rank_Sincerity', 'rank_Spellcraft', 'rank_Tea_Ceremony', 'rank_rhigh', 'rank_Athletics', 'rank_Battle', 'rank_Defense', 'rank_Horsemanship', 'rank_Hunting', 'rank_Iaijutsu', 'rank_Jiujutsu', 'rank_Chain_Weapons', 'rank_Heavy_Weapons', 'rank_Kenjutsu', 'rank_Knives', 'rank_Kyujutsu', 'rank_Ninjutsu', 'rank_Polearms', 'rank_Spears', 'rank_Staves', 'rank_WarFan', 'rank_AnimalHandling', 'rank_Commerce', 'rank_Craft', 'rank_Engineering', 'rank_Sailing', 'rank_Forgery', 'rank_Intimidation', 'rank_SleightofHand', 'rank_Stealth', 'rank_Temptation', 'BCourtier', 'BEtiquette', 'add_insight'],
eventString = [...elements, ...ranks].map(s => `change:${s}`).join(' ') +
' change:repeating_rehigh:rank_rehigh remove:repeating_rehigh' +
' change:repeating_rweap:rank_rweap remove:repeating_rweap' +
' change:repeating_rcraft:rank_rcraft remove:repeating_rcraft' +
' change:repeating_rlow:rank_rlow remove:repeating_rlow';
// This function does the actual calculation and attribute-setting after we have all the names
var calcFooInsight = function (repeatingNames) {
getAttrs([...elements, ...ranks, ...repeatingNames], function (values) {
let sum = elements.reduce((s, k) => (s + (parseInt(values[k]) * 10 || 0)), 0) +
ranks.reduce((s, k) => (s + (parseInt(values[k]) || 0)), 0) +
repeatingNames.reduce((s, k) => (s + (parseFloat(values[k]) || 0)), 0);
setAttrs({
foo_insight: Math.round(sum)
});
});
};
// Collect necessary data for calculation
on(eventString, function () {
getSectionIDs('repeating_rehigh', function (idArrayRehigh) {
getSectionIDs('repeating_rweap', function (idArrayRweap) {
getSectionIDs('repeating_rcraft', function (idArrayRcraft) {
getSectionIDs('repeating_rlow', function (idArrayRlow) {
let attrNamesRehigh = idArrayRehigh.map(id => "repeating_rehigh_" + id + "_rank_rehigh"),
attrNamesRweap = idArrayRweap.map(id => "repeating_rweap_" + id + "_rank_rweap"),
attrNamesRcraft = idArrayRcraft.map(id => "repeating_rcraft_" + id + "_rank_rcraft"),
attrNamesRlow = idArrayRlow.map(id => "repeating_rlow_" + id + "_rank_rlow");
calcFooInsight([...attrNamesRehigh, ...attrNamesRweap, ...attrNamesRcraft, ...attrNamesRlow]);
});
});
});
});
});
</script>
I think it has to be this section, but I'm still weak on this sheet worker thing: var calcFooInsight = function (repeatingNames) {
getAttrs([...elements, ...ranks, ...repeatingNames], function (values) {
let sum = elements.reduce((s, k) => (s + (parseInt(values[k]) * 10 || 0)), 0) +
ranks.reduce((s, k) => (s + (parseInt(values[k]) || 0)), 0) +
repeatingNames.reduce((s, k) => (s + (parseFloat(values[k]) || 0)), 0);
setAttrs({
foo_insight: Math.round(sum)
});
});
So I'm willing to accept that there might be something else I'm not seeing. Any ideas?