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 .
×

trouble with sheet worker script for custom sheet

Before I explain the issue, I need to explain how the system I made this custom sheet for works. Damage from attacks is tracked individually. Each damage causes an "injury" that grants a penalty to your actions due to the pain. If you suffer multiple injuries, only the highest penalty is counted. This penalty also stacks with penalties provided by armor and encumbrance. Here's how the injury penalty is determined; Severity of Injury Light Injury: Lost of 1 or 2 Life Points gives no penalty Serious Injury: Lost of 3 to 4 Life points gives a -1 penalty Grave injury: Losing between 5 and half your total Life points gives a -3 penalty Critical Injury: Losing greater than half your total Life points gives a penalty equal to the amount of Life Points lost. Anyway, the issue with the script is that it can add penalties from armor and encumbrance just fine but is inconsistent with injuries. Below shows a Light Injury, granting no penalty. I applied a second injury that is one severity level higher, granting a -1 penalty. So far so good. Now here is where the issue is. I applied a third injury that should have a penalty of -3 but it still only shows -1. Even with the 2 and 4 point injuries removed, the penalty still remains -1. The issue persists regardless of which square is filled in.
Here is the script in question. <script type="text/worker"> on("change:dicepenalty change:injuries1 change:injuries2 change:injuries3 change:injuries4 change:injuries5 change:weatherdam1 change:weatherdam2 change:weatherdam3 change:weatherdam4 change:weatherdam5 change:penalty_complete change:penaltyshield change:encpenalty change:hpmax sheet:opened", function() {     getAttrs(["injuries1", "injuries2", "injuries3", "injuries4", "injuries5", "injuries6", "weatherdam1", "weatherdam2", "weatherdam3", "weatherdam4", "weatherdam5", "weatherdam6", "penalty_complete", "penaltyshield", "encpenalty", "dicepenalty", "hpmax"], function(values) {         let inj1 = parseInt(values.injuries1) || 0;         let inj2 = parseInt(values.injuries2) || 0;         let inj3 = parseInt(values.injuries3) || 0;         let inj4 = parseInt(values.injuries4) || 0;         let inj5 = parseInt(values.injuries5) || 0;         let inj6 = parseInt(values.injuries6) || 0;         let wthr1 = parseInt(values.weatherdam1) || 0;         let wthr2 = parseInt(values.weatherdam2) || 0;         let wthr3 = parseInt(values.weatherdam3) || 0;         let wthr4 = parseInt(values.weatherdam4) || 0;         let wthr5 = parseInt(values.weatherdam5) || 0;         let wthr6 = parseInt(values.weatherdam6) || 0;         let hpmax = parseInt(values.hpmax) || 0;         let armor = parseInt(values.penalty_complete) || 0;         let shield = parseInt(values.penaltyshield) || 0;         let enc = parseInt(values.encpenalty) || 0;         let penalty = Math.floor(armor + shield + enc);         // If statement checking sheet variable         if (inj1 <= 2 && inj1 > inj2 && inj1 > inj3 && inj1 > inj4 && inj1 > inj5 && inj1 > inj6 && inj1 > wthr1 && inj1 > wthr2 && inj1 > wthr3 && inj1 > wthr4 && inj1 > wthr5 && inj1 > wthr6) {             penalty += 0;         }         else if (inj2 <= 2 && inj2 > inj1 && inj2 > inj3 && inj2 > inj4 && inj2 > inj5 && inj2 > inj6 && inj2 > wthr1 && inj2 > wthr2 && inj2 > wthr3 && inj2 > wthr4 && inj2 > wthr5 && inj2 > wthr6) {             penalty += 0;         }          else if (inj3 <= 2 && inj3 > inj1 && inj3 > inj2 && inj3 > inj4 && inj3 > inj5 && inj3 > inj6 && inj3 > wthr1 && inj3 > wthr2 && inj3 > wthr3 && inj3 > wthr4 && inj3 > wthr5 && inj3 > wthr6) {             penalty += 0;         }          else if (inj4 <= 2 && inj4 > inj1 && inj4 > inj2 && inj4 > inj3 && inj4 > inj5 && inj4 > inj6 && inj4 > wthr1 && inj4 > wthr2 && inj4 > wthr3 && inj4 > wthr4 && inj4 > wthr5 && inj4 > wthr6) {             penalty += 0;         }         else if (inj5 <= 2 && inj5 > inj1 && inj5 > inj2 && inj5 > inj3 && inj5 > inj4 && inj5 > inj6 && inj5 > wthr1 && inj5 > wthr2 && inj5 > wthr3 && inj5 > wthr4 && inj5 > wthr5 && inj5 > wthr6) {             penalty += 0;         }         else if (inj6 <= 2 && inj6 > inj1 && inj6 > inj2 && inj6 > inj3 && inj6 > inj4 && inj6 > inj5 && inj6 > wthr1 && inj6 > wthr2 && inj6 > wthr3 && inj6 > wthr4 && inj6 > wthr5 && inj6 > wthr6) {             penalty += 0;         }         else if (wthr1 <= 2 && wthr1 > inj1 && wthr1 > inj2 && wthr1 > inj3 && wthr1 > inj4 && wthr1 > inj5 && wthr1 > inj6 && wthr1 > wthr2 && wthr1 > wthr3 && wthr1 > wthr4 && wthr1 > wthr5 && wthr1 > wthr6) {             penalty += 0;         }         else if (wthr2 <= 2 && wthr2 > inj1 && wthr2 > inj2 && wthr2 > inj3 && wthr2 > inj4 && wthr2 > inj5 && wthr2 > inj6 && wthr2 > wthr1 && wthr2 > wthr3 && wthr2 > wthr4 && wthr2 > wthr5 && wthr2 > wthr6) {             penalty += 0;         }         else if (wthr3 <= 2 && wthr3 > inj1 && wthr3 > inj2 && wthr3 > inj3 && wthr3 > inj4 && wthr3 > inj5 && wthr3 > inj6 && wthr3 > wthr1 && wthr3 > wthr2 && wthr3 > wthr4 && wthr3 > wthr5 && wthr3 > wthr6) {             penalty += 0;         }         else if (wthr4 <= 2 && wthr4 > inj1 && wthr4 > inj2 && wthr4 > inj3 && wthr4 > inj4 && wthr4 > inj5 && wthr4 > inj6 && wthr4 > wthr1 && wthr4 > wthr2 && wthr4 > wthr3 && wthr4 > wthr5 && wthr4 > wthr6) {             penalty += 0;         }         else if (wthr5 <= 2 && wthr5 > inj1 && wthr5 > inj2 && wthr5 > inj3 && wthr5 > inj4 && wthr5 > inj5 && wthr5 > inj6 && wthr5 > wthr1 && wthr5 > wthr2 && wthr5 > wthr3 && wthr5 > wthr4 && wthr5 > wthr6) {             penalty += 0;         }         else if (wthr6 <= 2 && wthr6 > inj1 && wthr6 > inj2 && wthr6 > inj3 && wthr6 > inj4 && wthr6 > inj5 && wthr6 > inj6 && wthr6 > wthr1 && wthr6 > wthr2 && wthr6 > wthr3 && wthr6 > wthr4 && wthr6 > wthr5) {             penalty += 0;         }                           else if (inj1 = 3 && inj1 > inj2 && inj1 > inj3 && inj1 > inj4 && inj1 > inj5 && inj1 > inj6 && inj1 > wthr1 && inj1 > wthr2 && inj1 > wthr3 && inj1 > wthr4 && inj1 > wthr5 && inj1 > wthr6) {             penalty += -1;         }         else if (inj2 = 3 && inj2 > inj1 && inj2 > inj3 && inj2 > inj4 && inj2 > inj5 && inj2 > inj6 && inj2 > wthr1 && inj2 > wthr2 && inj2 > wthr3 && inj2 > wthr4 && inj2 > wthr5 && inj2 > wthr6) {             penalty += -1;         }          else if (inj3 = 3 && inj3 > inj1 && inj3 > inj2 && inj3 > inj4 && inj3 > inj5 && inj3 > inj6 && inj3 > wthr1 && inj3 > wthr2 && inj3 > wthr3 && inj3 > wthr4 && inj3 > wthr5 && inj3 > wthr6) {             penalty += -1;         }          else if (inj4 = 3 && inj4 > inj1 && inj4 > inj2 && inj4 > inj3 && inj4 > inj5 && inj4 > inj6 && inj4 > wthr1 && inj4 > wthr2 && inj4 > wthr3 && inj4 > wthr4 && inj4 > wthr5 && inj4 > wthr6) {             penalty += -1;         }         else if (inj5 = 3 && inj5 > inj1 && inj5 > inj2 && inj5 > inj3 && inj5 > inj4 && inj5 > inj6 && inj5 > wthr1 && inj5 > wthr2 && inj5 > wthr3 && inj5 > wthr4 && inj5 > wthr5 && inj5 > wthr6) {             penalty += -1;         }         else if (inj6 = 3 && inj6 > inj1 && inj6 > inj2 && inj6 > inj3 && inj6 > inj4 && inj6 > inj5 && inj6 > wthr1 && inj6 > wthr2 && inj6 > wthr3 && inj6 > wthr4 && inj6 > wthr5 && inj6 > wthr6) {             penalty += -1;         }         else if (wthr1 = 3 && wthr1 > inj1 && wthr1 > inj2 && wthr1 > inj3 && wthr1 > inj4 && wthr1 > inj5 && wthr1 > inj6 && wthr1 > wthr2 && wthr1 > wthr3 && wthr1 > wthr4 && wthr1 > wthr5 && wthr1 > wthr6) {             penalty += -1;         }         else if (wthr2 = 3 && wthr2 > inj1 && wthr2 > inj2 && wthr2 > inj3 && wthr2 > inj4 && wthr2 > inj5 && wthr2 > inj6 && wthr2 > wthr1 && wthr2 > wthr3 && wthr2 > wthr4 && wthr2 > wthr5 && wthr2 > wthr6) {             penalty += -1;         }         else if (wthr3 = 3 && wthr3 > inj1 && wthr3 > inj2 && wthr3 > inj3 && wthr3 > inj4 && wthr3 > inj5 && wthr3 > inj6 && wthr3 > wthr1 && wthr3 > wthr2 && wthr3 > wthr4 && wthr3 > wthr5 && wthr3 > wthr6) {             penalty += -1;         }         else if (wthr4 = 3 && wthr4 > inj1 && wthr4 > inj2 && wthr4 > inj3 && wthr4 > inj4 && wthr4 > inj5 && wthr4 > inj6 && wthr4 > wthr1 && wthr4 > wthr2 && wthr4 > wthr3 && wthr4 > wthr5 && wthr4 > wthr6) {             penalty += -1;         }         else if (wthr5 = 3 && wthr5 > inj1 && wthr5 > inj2 && wthr5 > inj3 && wthr5 > inj4 && wthr5 > inj5 && wthr5 > inj6 && wthr5 > wthr1 && wthr5 > wthr2 && wthr5 > wthr3 && wthr5 > wthr4 && wthr5 > wthr6) {             penalty += -1;         }         else if (wthr6 = 3 && wthr6 > inj1 && wthr6 > inj2 && wthr6 > inj3 && wthr6 > inj4 && wthr6 > inj5 && wthr6 > inj6 && wthr6 > wthr1 && wthr6 > wthr2 && wthr6 > wthr3 && wthr6 > wthr4 && wthr6 > wthr5) {             penalty += -1;         }                  else if (inj1 = 4 && inj1 > inj2 && inj1 > inj3 && inj1 > inj4 && inj1 > inj5 && inj1 > inj6 && inj1 > wthr1 && inj1 > wthr2 && inj1 > wthr3 && inj1 > wthr4 && inj1 > wthr5 && inj1 > wthr6) {             penalty += -1;         }          else if (inj2 = 4 && inj2 > inj1 && inj2 > inj3 && inj2 > inj4 && inj2 > inj5 && inj2 > inj6 && inj2 > wthr1 && inj2 > wthr2 && inj2 > wthr3 && inj2 > wthr4 && inj2 > wthr5 && inj2 > wthr6) {             penalty += -1;         }          else if (inj3 = 4 && inj3 > inj1 && inj3 > inj2 && inj3 > inj4 && inj3 > inj5 && inj3 > inj6 && inj3 > wthr1 && inj3 > wthr2 && inj3 > wthr3 && inj3 > wthr4 && inj3 > wthr5 && inj3 > wthr6) {             penalty += -1;         }          else if (inj4 = 4 && inj4 > inj1 && inj4 > inj2 && inj4 > inj3 && inj4 > inj5 && inj4 > inj6 && inj4 > wthr1 && inj4 > wthr2 && inj4 > wthr3 && inj4 > wthr4 && inj4 > wthr5 && inj4 > wthr6) {             penalty += -1;         }         else if (inj5 = 4 && inj5 > inj1 && inj5 > inj2 && inj5 > inj3 && inj5 > inj4 && inj5 > inj6 && inj5 > wthr1 && inj5 > wthr2 && inj5 > wthr3 && inj5 > wthr4 && inj5 > wthr5 && inj5 > wthr6) {             penalty += -1;         }         else if (inj6 = 4 && inj6 > inj1 && inj6 > inj2 && inj6 > inj3 && inj6 > inj4 && inj6 > inj5 && inj6 > wthr1 && inj6 > wthr2 && inj6 > wthr3 && inj6 > wthr4 && inj6 > wthr5 && inj6 > wthr6) {             penalty += -1;         }         else if (wthr1 = 4 && wthr1 > inj1 && wthr1 > inj2 && wthr1 > inj3 && wthr1 > inj4 && wthr1 > inj5 && wthr1 > inj6 && wthr1 > wthr2 && wthr1 > wthr3 && wthr1 > wthr4 && wthr1 > wthr5 && wthr1 > wthr6) {             penalty += -1;         }         else if (wthr2 = 4 && wthr2 > inj1 && wthr2 > inj2 && wthr2 > inj3 && wthr2 > inj4 && wthr2 > inj5 && wthr2 > inj6 && wthr2 > wthr1 && wthr2 > wthr3 && wthr2 > wthr4 && wthr2 > wthr5 && wthr2 > wthr6) {             penalty += -1;         }         else if (wthr3 = 4 && wthr3 > inj1 && wthr3 > inj2 && wthr3 > inj3 && wthr3 > inj4 && wthr3 > inj5 && wthr3 > inj6 && wthr3 > wthr1 && wthr3 > wthr2 && wthr3 > wthr4 && wthr3 > wthr5 && wthr3 > wthr6) {             penalty += -1;         }         else if (wthr4 = 4 && wthr4 > inj1 && wthr4 > inj2 && wthr4 > inj3 && wthr4 > inj4 && wthr4 > inj5 && wthr4 > inj6 && wthr4 > wthr1 && wthr4 > wthr2 && wthr4 > wthr3 && wthr4 > wthr5 && wthr4 > wthr6) {             penalty += -1;         }         else if (wthr5 = 4 && wthr5 > inj1 && wthr5 > inj2 && wthr5 > inj3 && wthr5 > inj4 && wthr5 > inj5 && wthr5 > inj6 && wthr5 > wthr1 && wthr5 > wthr2 && wthr5 > wthr3 && wthr5 > wthr4 && wthr5 > wthr6) {             penalty += -1;         }         else if (wthr6 = 4 && wthr6 > inj1 && wthr6 > inj2 && wthr6 > inj3 && wthr6 > inj4 && wthr6 > inj5 && wthr6 > inj6 && wthr6 > wthr1 && wthr6 > wthr2 && wthr6 > wthr3 && wthr6 > wthr4 && wthr6 > wthr5) {             penalty += -1;         }                  else if (inj1 >= 5 && inj1 > inj2 && inj1 > inj3 && inj1 > inj4 && inj1 > inj5 && inj1 > inj6 && inj1 > wthr1 && inj1 > wthr2 && inj1 > wthr3 && inj1 > wthr4 && inj1 > wthr5 && inj1 > wthr6) {             penalty += -3;         }          else if (inj2 >= 5 && inj2 > inj1 && inj2 > inj3 && inj2 > inj4 && inj2 > inj5 && inj2 > inj6 && inj2 > wthr1 && inj2 > wthr2 && inj2 > wthr3 && inj2 > wthr4 && inj2 > wthr5 && inj2 > wthr6) {             penalty += -3;         }          else if (inj3 >= 5 && inj3 > inj1 && inj3 > inj2 && inj3 > inj4 && inj3 > inj5 && inj3 > inj6 && inj3 > wthr1 && inj3 > wthr2 && inj3 > wthr3 && inj3 > wthr4 && inj3 > wthr5 && inj3 > wthr6) {             penalty += -3;         }          else if (inj4 >= 5 && inj4 > inj1 && inj4 > inj2 && inj4 > inj3 && inj4 > inj5 && inj4 > inj6 && inj4 > wthr1 && inj4 > wthr2 && inj4 > wthr3 && inj4 > wthr4 && inj4 > wthr5 && inj4 > wthr6) {             penalty += -3;         }         else if (inj5 >= 5 && inj5 > inj1 && inj5 > inj2 && inj5 > inj3 && inj5 > inj4 && inj5 > inj6 && inj5 > wthr1 && inj5 > wthr2 && inj5 > wthr3 && inj5 > wthr4 && inj5 > wthr5 && inj5 > wthr6) {             penalty += -3;         }         else if (inj6 >= 5 && inj6 > inj1 && inj6 > inj2 && inj6 > inj3 && inj6 > inj4 && inj6 > inj5 && inj6 > wthr1 && inj6 > wthr2 && inj6 > wthr3 && inj6 > wthr4 && inj6 > wthr5 && inj6 > wthr6) {             penalty += -3;         }         else if (wthr1 >= 5 && wthr1 > inj1 && wthr1 > inj2 && wthr1 > inj3 && wthr1 > inj4 && wthr1 > inj5 && wthr1 > inj6 && wthr1 > wthr2 && wthr1 > wthr3 && wthr1 > wthr4 && wthr1 > wthr5 && wthr1 > wthr6) {             penalty += -3;         }         else if (wthr2 >= 5 && wthr2 > inj1 && wthr2 > inj2 && wthr2 > inj3 && wthr2 > inj4 && wthr2 > inj5 && wthr2 > inj6 && wthr2 > wthr1 && wthr2 > wthr3 && wthr2 > wthr4 && wthr2 > wthr5 && wthr2 > wthr6) {             penalty += -3;         }         else if (wthr3 >= 5 && wthr3 > inj1 && wthr3 > inj2 && wthr3 > inj3 && wthr3 > inj4 && wthr3 > inj5 && wthr3 > inj6 && wthr3 > wthr1 && wthr3 > wthr2 && wthr3 > wthr4 && wthr3 > wthr5 && wthr3 > wthr6) {             penalty += -3;         }         else if (wthr4 >= 5 && wthr4 > inj1 && wthr4 > inj2 && wthr4 > inj3 && wthr4 > inj4 && wthr4 > inj5 && wthr4 > inj6 && wthr4 > wthr1 && wthr4 > wthr2 && wthr4 > wthr3 && wthr4 > wthr5 && wthr4 > wthr6) {             penalty += -3;         }         else if (wthr5 >= 5 && wthr5 > inj1 && wthr5 > inj2 && wthr5 > inj3 && wthr5 > inj4 && wthr5 > inj5 && wthr5 > inj6 && wthr5 > wthr1 && wthr5 > wthr2 && wthr5 > wthr3 && wthr5 > wthr4 && wthr5 > wthr6) {             penalty += -3;         }         else if (wthr6 >= 5 && wthr6 > inj1 && wthr6 > inj2 && wthr6 > inj3 && wthr6 > inj4 && wthr6 > inj5 && wthr6 > inj6 && wthr6 > wthr1 && wthr6 > wthr2 && wthr6 > wthr3 && wthr6 > wthr4 && wthr6 > wthr5) {             penalty += -3;         }                  else if (inj1 > (hpmax/2) && inj1 > inj2 && inj1 > inj3 && inj1 > inj4 && inj1 > inj5 && inj1 > inj6 && inj1 > wthr1 && inj1 > wthr2 && inj1 > wthr3 && inj1 > wthr4 && inj1 > wthr5 && inj1 > wthr6) {             penalty -= inj1;         }          else if (inj2 > (hpmax/2) && inj2 > inj1 && inj2 > inj3 && inj2 > inj4 && inj2 > inj5 && inj2 > inj6 && inj2 > wthr1 && inj2 > wthr2 && inj2 > wthr3 && inj2 > wthr4 && inj2 > wthr5 && inj2 > wthr6) {             penalty -= inj2;         }          else if (inj3 > (hpmax/2) && inj3 > inj1 && inj3 > inj2 && inj3 > inj4 && inj3 > inj5 && inj3 > inj6 && inj3 > wthr1 && inj3 > wthr2 && inj3 > wthr3 && inj3 > wthr4 && inj3 > wthr5 && inj3 > wthr6) {             penalty -= inj3;         }          else if (inj4 > (hpmax/2) && inj4 > inj1 && inj4 > inj2 && inj4 > inj3 && inj4 > inj5 && inj4 > inj6 && inj4 > wthr1 && inj4 > wthr2 && inj4 > wthr3 && inj4 > wthr4 && inj4 > wthr5 && inj4 > wthr6) {             penalty -= inj4;         }         else if (inj5 > (hpmax/2) && inj5 > inj1 && inj5 > inj2 && inj5 > inj3 && inj5 > inj4 && inj5 > inj6 && inj5 > wthr1 && inj5 > wthr2 && inj5 > wthr3 && inj5 > wthr4 && inj5 > wthr5 && inj5 > wthr6) {             penalty -= inj5;         }         else if (inj6 > (hpmax/2) && inj6 > inj1 && inj6 > inj2 && inj6 > inj3 && inj6 > inj4 && inj6 > inj5 && inj6 > wthr1 && inj6 > wthr2 && inj6 > wthr3 && inj6 > wthr4 && inj6 > wthr5 && inj6 > wthr6) {             penalty -= inj6;         }         else if (wthr1 > (hpmax/2) && wthr1 > inj1 && wthr1 > inj2 && wthr1 > inj3 && wthr1 > inj4 && wthr1 > inj5 && wthr1 > inj6 && wthr1 > wthr2 && wthr1 > wthr3 && wthr1 > wthr4 && wthr1 > wthr5 && wthr1 > wthr6) {             penalty -= wthr1;         }         else if (wthr2 > (hpmax/2) && wthr2 > inj1 && wthr2 > inj2 && wthr2 > inj3 && wthr2 > inj4 && wthr2 > inj5 && wthr2 > inj6 && wthr2 > wthr1 && wthr2 > wthr3 && wthr2 > wthr4 && wthr2 > wthr5 && wthr2 > wthr6) {             penalty -= wthr2;         }         else if (wthr3 > (hpmax/2) && wthr3 > inj1 && wthr3 > inj2 && wthr3 > inj3 && wthr3 > inj4 && wthr3 > inj5 && wthr3 > inj6 && wthr3 > wthr1 && wthr3 > wthr2 && wthr3 > wthr4 && wthr3 > wthr5 && wthr3 > wthr6) {             penalty -= wthr3;         }         else if (wthr4 > (hpmax/2) && wthr4 > inj1 && wthr4 > inj2 && wthr4 > inj3 && wthr4 > inj4 && wthr4 > inj5 && wthr4 > inj6 && wthr4 > wthr1 && wthr4 > wthr2 && wthr4 > wthr3 && wthr4 > wthr5 && wthr4 > wthr6) {             penalty -= wthr4;         }         else if (wthr5 > (hpmax/2) && wthr5 > inj1 && wthr5 > inj2 && wthr5 > inj3 && wthr5 > inj4 && wthr5 > inj5 && wthr5 > inj6 && wthr5 > wthr1 && wthr5 > wthr2 && wthr5 > wthr3 && wthr5 > wthr4 && wthr5 > wthr6) {             penalty -= wthr5;         }         else if (wthr6 > (hpmax/2) && wthr6 > inj1 && wthr6 > inj2 && wthr6 > inj3 && wthr6 > inj4 && wthr6 > inj5 && wthr6 > inj6 && wthr6 > wthr1 && wthr6 > wthr2 && wthr6 > wthr3 && wthr6 > wthr4 && wthr6 > wthr5) {             penalty -= wthr6;         }         else {             penalty += 0;         }         // Write the result back to another sheet variable         setAttrs({dicepenalty: penalty});     }); }); </script>
1793392915

Edited 1793393058
I won't claim to be any kind of Javascript expert, but one obvious issue is that your tests for equality use "=" rather than "==", javascript uses the former for assignment and the latter for a one form of equality test (I can't tell you how many times I've done that...) So: else if (inj1 = 3 && inj1 > inj2 && inj1 > inj3 && inj1 > inj4 && inj1 > inj5 && inj1 > inj6 && inj1 > wthr1 && inj1 > wthr2 && inj1 > wthr3 && inj1 > wthr4 && inj1 > wthr5 && inj1 > wthr6) {             penalty += -1;         } is probably evaluating to true and preventing the execution of later tests in the if-then-else structure.
That was it. Once all single = were replaced with the double ==, it started working properly Thanks a million!