Problem With Values

I have a screen where I’m checking to see if a skill tier has levelled. Each skill has 4-5 tiers it can reach, with a target score to attain the tier. Target score is calculated by adding two character stats. Construction for instance is sleight + aptitude. The first stat is a stat. The second stat is a sensory stat.

In the character development screen there are two buttons for switching from one panel to another. Character button and craft skills. I have to press the craft skills button twice before the change is noticed in the score value for the craft score. Oddly, I believe the score it’s looking for is the right score, it shows up in character.crafts where I want it, as the right value. Except it only uses the modified score when I go into the screen a second time. I update the score by pipping the stats in character screen.

I look in the character object and the score is 28 after I update it. But it shows 21 on the first button press. On the second it uses the score 28.

This is my pipStats function on character

this.CharacterClass.prototype.pipCrafts = function()
{

      var skillsObj = this.crafts;
      console.log(this);

      for(skillIndex in skillsObj)
      {

            for(tierIndex in skillsObj[skillIndex].tiers)
            {

                 
                  if(skillsObj[skillIndex].score >= skillsObj[skillIndex].tiers[tierIndex].targetScore)
                  {
                        console.log("CRAFT TIERS UPDATED");
                        console.log("Craft: " + skillsObj[skillIndex].skill);
                        console.log("Craft Tier: " + skillsObj[skillIndex].tier);
                        console.log("Craft Score: " + skillsObj[skillIndex].score);
                        console.log("Target Score: " + skillsObj[skillIndex].tiers[tierIndex].targetScore);
                        this.crafts[skillIndex].tier = skillsObj[skillIndex].tiers[tierIndex].tier;

                  }else{

                        console.log("Score Missed");
                        console.log("Craft: " + skillsObj[skillIndex].skill);
                        console.log("Craft Tier: " + skillsObj[skillIndex].tier);
                        console.log("Craft Score: " + skillsObj[skillIndex].score);
                        console.log("Target Score: " + skillsObj[skillIndex].tiers[tierIndex].targetScore);

                  }

            }

      }

};

carftSkillsButton Press

 // click craftsButton
                                           if (event.target.matches("#craftSkillsButton") || event.target.closest("#craftSkillsButton"))
                                           {

                                                  console.log("CHARACTER CRAFTS HERE");
                                                  console.log(character.crafts);

                                                    for(charSkillsIndex in character.crafts)
                                                    {

                                                       if(equationHelper.crafts[index].skill == character.crafts[charSkillsIndex].skill)
                                                        {
                                                                                          // we have matched an owned skill with all possible skills
                                                              var amount = parseInt(character.stats[skillSplit[0]]) + parseInt(character.sensoryStats[skillSplit[1]]);
                                                              character.crafts[charSkillsIndex].score = parseInt(amount);
                                                        }
                                                    }

                                                console.log("Very Top");
                                                console.log(character);
                                                character.pipCrafts();

                                                // fetch craft skills screen
                                                var dataSend = {userToken:userResult.token,
                                                              userSerial:userResult.serial,
                                                              html:"craft-skills-character-screen"};
                                                  $.ajax({
                                                      url: 'http://localhost/OtherRealms/php/scripts/fetch_html.php',
                                                      dataType: 'json',
                                                      type: 'POST',
                                                      contentType: 'application/json; charset=utf-8',
                                                      data: dataSend,
                                                      success: function( data, textStatus, jQxhr ){

                                                          if(data.hasOwnProperty("message"))
                                                          {

                                                            switch(data.message)
                                                            {

                                                              case "success":
                                                                   

                                                                 console.log("html retrieve");
                                                                 console.log(character);

                                                                 document.getElementById("pageWrapper").innerHTML = "";
                                                                 document.getElementById("pageWrapper").innerHTML = data.html;
                                                                 document.querySelector("#skillPointCount").innerHTML = "";
                                                                 document.querySelector("#skillPointCount").innerHTML = character.skillPoints + " SP";

                                                                 
                                                                  // fetch skill balances
                                                                 var equationData = {"type":"crafts"};

                                                                  $.ajax({
                                                                      url: 'http://localhost/OtherRealms/php/scripts/fetch_balance_equations.php',
                                                                      dataType: 'json',
                                                                      type: 'POST',
                                                                      contentType: 'application/json; charset=utf-8',
                                                                      data: equationData,
                                                                      success: function( data, textStatus, jQxhr ){

                                                                        if(data.hasOwnProperty("message"))
                                                                        {

                                                                          switch(data.message)
                                                                          {

                                                                              case "success":
                                                                                    // place equations for the crafts
                                                                                    equationHelper.crafts = data;
                                                                                  
                                                                                    for(equation in equationHelper.crafts)
                                                                                    {
                                                                                      if(equation !== "success")
                                                                                      {
                                                                                          if(equationHelper.crafts[equation].skill)
                                                                                          {
                                                                                          
                                                                                            var element =  document.querySelectorAll("#"+equationHelper.crafts[equation].skill + "Equation");
                                                                                           
                                                                                            element[0].innerHTML = "";
                                                                                            element[0].innerHTML = equationHelper.crafts[equation].equation;
                                                                                          
                                                                                          }


                                                                                        }

                                                                                    }

                                                                         for(skill in character.crafts)
                                                                            {

                                                                                 // remove buy button and set skill per aquired skills
                                                                                 document.querySelector("#" + character.crafts[skill].skill + "Buy").remove();
                                                                                 document.querySelector("#" + character.crafts[skill].skill + "Tier").innerHTML = "<span>" + character.crafts[skill].tier + "</span>";

                                                                                 // end loop through skills
                                                                            }

                                                                          for(index in equationHelper.crafts)
                                                                            {
                                                                            

                                                                              if(index !== "message")
                                                                              {

                                                                                  var skillSplit = equationHelper.crafts[index].equation.split("+");

                                                                                    for(element in skillSplit)
                                                                                    {

                                                                                      skillSplit[element] = skillSplit[element].trim();

                                                                                    }
                                                                                   
                                                                                   
                                                                                    var box = document.querySelector("#" + equationHelper.crafts[index].skill + "Score");
                                                                                    box.innerHTML = "0";

                                                                                  // test if character has the skill, if so set the box to contain the balance

                                                                                  for(charSkillsIndex in character.crafts)
                                                                                  {

                                                                                      if(equationHelper.crafts[index].skill == character.crafts[charSkillsIndex].skill)
                                                                                      {

                                                                                          // we have matched an owned skill with all possible skills
                                                                                          var amount = parseInt(character.stats[skillSplit[0]]) + parseInt(character.sensoryStats[skillSplit[1]]);
                                                                                          character.crafts[charSkillsIndex].score = parseInt(amount);
                                                                                           box.innerHTML = amount;

                                                                                      }

                                                                                  }
                                                                                  
                                                                              }

                                                                            }
                                                                               

                                                                        // update balance boxes for the crafts

                                                                              break;

                                                                          }
                                                                            
                                                                        }

                                                                       
                                                                          
                                                                      },
                                                                      error: function( jqXhr, textStatus, errorThrown ){
                                                                          console.log( errorThrown );
                                                                      }
                                                                      // end fetch skill balances
                                                                  });
                                                              break;

                                                            }

                                                          }
                                                          
                                                      },
                                                      error: function( jqXhr, textStatus, errorThrown ){
                                                          console.log( errorThrown );
                                                      }
                                                  });

                                                  console.log("Character Bottom");
                                                  console.log(character);

                                             // end craft skills button press     
                                           }

I’m… not really sure which lines you’re trying to highlight to us, because we dont know your code.

You’re giving us the definition of the problem, which is good. But with a script that long… point us at the line you think isnt doing what its supposed to be doing?

If you are confident that the data is correct why not just write it to the screen using js instead of sending it to the server for php to refresh the page?