Wow! I learned quite a bit from that post. I had a couple dozen functions, each with their own script block. I'd made a lot of progress on building up my java-script proficiency. I was just starting to wonder what some of that other code was for. For instance, I don't know what any of the following do: const int = (value, error = 0) => parseInt(value) || error ; on('change:experience', () => { getAttrs(['experience'], values => { I think it's mostly that I haven't wrapped my mind around "=>" yet. I've looked at w3schools, and I have an idea. It just hasn't crystallized in my head just yet. You were right about the issue with these lines: const nxt_level = exp_table.findIndex(element => element > exp) || 31; const cur_level = nxt_level - 1; However, one of your replacement lines had an issue too: const nxt_level = nxt_level + 1; I think you meant: const nxt_level = cur_level + 1; That said, I never really explained what I was going for. The variable "nxt_level" is supposed to hold the amount of experience needed to get to the next level, so I replaced it with: const nxt_level = exp_table[cur_level]-exp; In addition, in the course of fixing this, I did some thorough examination through console.log(), and decided that I needed to remove all my functions and replace them one by one, testing each. When I wrote them, I wasn't looking at console.log(), and there is an error thrown from one of them that I'm still looking for. Every one I've put back so far is working correctly. The " || 31" still resulted in an error. I tried to catch it, but that didn't work, so I used an if statement. Thanks again for your help = ). Here is the final code, in case anyone wants to see it: <div class="clevel blueBackground blueBorderRight1 section">
<div class="fieldLabel white section">Level</div>
<input name="attr_current_level" type="hidden">
<span class="field derived" name="attr_current_level"></span>
</div>
<div class="experi blueBackground section">
<div class="fieldLabel white section">Experience</div>
<input class="field manual23" name="attr_experience" type="number" min='0'>
</div>
<div class="nxtlvl blueBackground section">
<div class="fieldLabel white section">Next Level</div>
<input name="attr_next_level" type="hidden">
<span class="field derived" name="attr_next_level"></span>
</div>
<script type="text/worker">
const int = (value, error = 0) => parseInt(value) || error;
<!-- set current level and next level experience -->
on('change:experience', () => {
getAttrs(['experience'], values => {
const exp = int(values.experience);
const exp_table = [
/* 0 <= */ -1,
/* 1 <= */ 1500,
/* 2 <= */ 4500,
/* 3 <= */ 13500,
/* 4 <= */ 25500,
/* 5 <= */ 40500,
/* 6 <= */ 58500,
/* 7 <= */ 79500,
/* 8 <= */ 103500,
/* 9 <= */ 130500,
/* 10 <= */ 160500,
/* 11 <= */ 193500,
/* 12 <= */ 229500,
/* 13 <= */ 268500,
/* 14 <= */ 310500,
/* 15 <= */ 355500,
/* 16 <= */ 403500,
/* 17 <= */ 454500,
/* 18 <= */ 508500,
/* 19 <= */ 565500,
/* 20 <= */ 625500,
/* 21 <= */ 688500,
/* 22 <= */ 754500,
/* 23 <= */ 823500,
/* 24 <= */ 895500,
/* 25 <= */ 970500,
/* 26 <= */ 1048500,
/* 27 <= */ 1129500,
/* 28 <= */ 1213500,
/* 29 <= */ 1300500,
/* 30 <= */ 1390500
];
var cur_level = "Yes!";
var nxt_level = "Apotheosis!";
if (exp < 1390500) {
cur_level = exp_table.findIndex(element => element > exp);
nxt_level = exp_table[cur_level]-exp;
}
console.log(
'current_level: ' + cur_level + '\n',
'next_level: ' + nxt_level
);
setAttrs({
current_level: cur_level,
next_level: nxt_level
});
});
});
</script>