Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Skill Doesn't Calculate a Negative Value

I am having an issue on my sheet where skills are not applying the armor penalty to skills correctly. If I use positive penalty of 5 it will add 5 to the skill, but if I use -5 it will not calculate it and apply it. Ideally, there should never be a positive penalty and only negatives. Is there anything here that can be explained why it might not be subtracting from the skill?  My coding skills are minimal.         on("change:acrobatics-base change:acrobatics-mod change:total_armor_penalty change:usearmorpenalty", function (eventinfo) {         getAttrs(["acrobatics-base","acrobatics-mod","total_armor_penalty","useArmorPenalty"], function (values) {                 var acrobaticsBase = parseInt(values["acrobatics-base"]);                 var acrobaticsMod = parseInt(values["acrobatics-mod"]);                 var penaltyVal = parseInt(values["total_armor_penalty"]);                 var usePenalty = parseInt(values["useArmorPenalty"]);                 if(usePenalty==1){                     if((acrobaticsMod+penaltyVal)>=0){                         setAttrs({                             'acrobatics': acrobaticsBase+acrobaticsMod+penaltyVal                         });                     }                     else{                         setAttrs({                             'acrobatics': acrobaticsBase                         });                     }                 }                 else{                     setAttrs({                         'acrobatics': acrobaticsBase+acrobaticsMod                     });                 }             });         });
I just realized that it is calculating correctly. It doesn't modify the base skill, but it does modify the mod being added. So if the base skill is at 20 and the mod is 0, it will not appear to be calculating, since it will not lower it below the base. Figured it out!
1581623901

Edited 1581654726
GiGs
Pro
Sheet Author
API Scripter
I have two suggestions for optimising your worker. First, when using parseInt, handle failure safely by setting a default value, like so: var acrobaticsBase = parseInt(values["acrobatics-base"]) || 0; Since all attributes are started as strings, you can sometimes have invalid data (even an empty cell might sometimes not be recognised as the number zero), especially if you then try to perform arithmetic with it.  So it's a good idea to make sure it's always a number by setting a default. Secondly, its a good idea to get into the habit of keeping the number of setAttrs calls in your workers to just one. In your worker here, you don't really need to, since no matter how you enter the worker, your path will only take you to one setAttrs. But it's still good to get in practice of building your workers to make sure you only have one setAttrs. You can do that easily like so: let acrobatics = 0; if (usePenalty == 1) {     if ((acrobaticsMod + penaltyVal) >= 0) {         acrobatics = Base + acrobaticsMod + penaltyVal;     } else {         acrobatics = acrobaticsBase;     } } else {     acrobatics = acrobaticsBase + acrobaticsMod; } setAttrs({     'acrobatics': acrobatics }); There are a few ways you could condense the if statement too. This should do the same job let acrobatics = 0; if (usePenalty == 1 && (acrobaticsMod + penaltyVal) >= 0) {     acrobatics = Base + acrobaticsMod + penaltyVal; } else if (usePenalty == 1) {     acrobatics = acrobaticsBase; } else {     acrobatics = acrobaticsBase + acrobaticsMod; } setAttrs({     'acrobatics': acrobatics }); if usePenalty can only be 0 or 1 (it's a checkbox) you dont need to use ==1, just usePenalty, like so }  else   if  ( usePenalty ) { In the above code && is the AND operator - if all linked conditions are true, the if condition is true.
Thank you for elaborating on this. I'll experiment and try out the condensed versions. Maybe one day the logic will start to make sense to me.