
Hello I seek guidance on this matter because I'm absolute noob on this and cannot figure it out.
I try to calculate a strength mod based on the strength value with the sheet worker. But it's not linear and I tried to handle things with "if"
Well I haven't got any success... Since there are a lot of awesome people on the forum, I think it'll be quicker to ask rather than to solve it myself :p
This is the code so far, I fiddled it a lot.
The end purpose is to set the others stats also, but currently only working on strength :)
THX for reading (not native speaker, sorry for any mistake)
<script type="text/worker">
on("change:attr_strength change:attr_dexterity change:attr_constitution change:attr_intelligence change:attr_wisdom change attr_charisma sheet:opened", function() {
getAttrs(["attr_strength","attr_dexterity","attr_constitution","attr_intelligence","attr_wisdom","attr_charisma"], function(values) {
let stat1 = parseInt(values.attr_strength)||0;
let mod1;
if (stat1=3) {setAttrs({mod1=-3});}
else if (stat1<6) {setAttrs({mod1=-2});}
else if (stat1<9) {setAttrs({mod1=-1});}
else if (stat1<13) {setAttrs({mod1=-0});}
else if (stat1<16) {setAttrs({mod1=1});}
else if (stat1<18) {setAttrs({mod1=2});}
else {setAttrs({mod1=3});}
setAttrs({
"attr_strengthMod": mod1
});
});
});
</script>