Your code is pretty confusing here var skl_rnk_bon = 0; if (skl_rnk > -1 && skl_rnk < 13)
const skl_rnk_bon = skill_rank_bonus_table[skl_rnk]; You should start the if statement on a new line. This looks like an error of scope. The error is most apparent if you break the code out into its non-abbreviated form: if (skl_rnk > -1 && skl_rnk < 13) {
const skl_rnk_bon = skill_rank_bonus_table[skl_rnk];
} Anything after an if statement is in its own scope. You can do this (and I often do) for shorter cleaner code: if (skl_rnk > -1 && skl_rnk < 13) skl_rnk_bon = skill_rank_bonus_table[skl_rnk]; When you have only one thing in an if statement, you dont need the { } brackets, but you should think of them as still being there. So, this line const skl_rnk_bon = skill_rank_bonus_table[skl_rnk]; is inside the scope of the if statement. The problem here is when you declare variables inside a scope, using const or let, they exist only within that scope. Even if it has the same name as another variable, it is a different instance, and loses its value when you move on from the if statement. So when you reach this setAttrs({repeating_skills_skill_rank_bonus: skl_rnk_bon}); that version of skl_rank_bon doesnt exist, only the first version with a value of 0 still exists. This is easily solved, just by removing the const from that earlier line. on('change:repeating_skills:skill_rank', () => { getAttrs(['repeating_skills_skill_rank'], values => { const skl_rnk = int(values.repeating_skills_skill_rank); const skill_rank_bonus_table = [ /* 0 */ 0, /* 1 */ 30, /* 2 */ 35, /* 3 */ 40, /* 4 */ 45, /* 5 */ 50, /* 6 */ 60, /* 7 */ 70, /* 8 */ 80, /* 9 */ 90, /* 10 */ 95, /* 11 */ 100, /* 12 */ 105 ]; var skl_rnk_bon = 0; if (skl_rnk > -1 && skl_rnk < 13) skl_rnk_bon = skill_rank_bonus_table[skl_rnk]; console.log('repeating_skills_skill_rank_bonus: ' + skl_rnk_bon); setAttrs({repeating_skills_skill_rank_bonus: skl_rnk_bon}); }); }); Or, for more clarity, add the scope brackets to the if statement: on('change:repeating_skills:skill_rank', () => { getAttrs(['repeating_skills_skill_rank'], values => { const skl_rnk = int(values.repeating_skills_skill_rank); const skill_rank_bonus_table = [ /* 0 */ 0, /* 1 */ 30, /* 2 */ 35, /* 3 */ 40, /* 4 */ 45, /* 5 */ 50, /* 6 */ 60, /* 7 */ 70, /* 8 */ 80, /* 9 */ 90, /* 10 */ 95, /* 11 */ 100, /* 12 */ 105 ]; var skl_rnk_bon = 0; if (skl_rnk > -1 && skl_rnk < 13) { skl_rnk_bon = skill_rank_bonus_table[skl_rnk]; } console.log('repeating_skills_skill_rank_bonus: ' + skl_rnk_bon); setAttrs({repeating_skills_skill_rank_bonus: skl_rnk_bon}); }); });