Level Up Crash

User: Frogboy
Bug: Crash on level up
How to Replicate the Bug:
  • Create a new project
  • Increase the maximum number of skills to 11
  • Assign skill 11 to be gained by Harold at level 2
  • Decrease the maximum number of skills back to 10
  • Set the slime to give 100XP. Might as well set the Slime to 1HP as well for quick testing.
  • Do a battle test against the Slime either in game or in the editor
  • When you win the battle, the game will try to assign this removed skill to Harold and crash
Other: While this bug is the result of user error, it's probably something that should be handled without crashing the game.

bug.png​

You can fix this by simply adding a check to make sure the skill exists.
Code:
Game_Actor.prototype.displayLevelUp = function(newSkills) {
    var text = TextManager.levelUp.format(this._name, TextManager.level, this._level);
    $gameMessage.newPage();
    $gameMessage.add(text);
    newSkills.forEach(function(skill) {
        if (skill) {
            $gameMessage.add(TextManager.obtainSkill.format(skill.name));
      } 
    });
};

Original thread: https://forums.rpgmakerweb.com/threads/level-up-crash.88387/