Reaching Max level gives me a Health value of 0/0

just as the title says, Reaching Max level gives me a Health value of 0/0. How can I prevent this, where can I edit or put a check so that when the player reaches the maximum level it should return the previous levels maximum health value or greater.

I think I am having this issue is because I have no more health value on the progression scriptable object when n max level is reached.


Not sure if its the best way, but i guess you could try in BaseStats,
simply add one serialize field int for maxLevel.
Then in UpdateLevel() something like this, to prevent further leveling up

        public void UpdateLevel()
        {
            if(currentLevel.value == maxLevel) { return; }

            int newLevel = CalculateLevel();
            if (newLevel > currentLevel.value)
            {
                currentLevel.value = newLevel;
                LevelUpEffect();
                onLevelUp();
            }
        }

I think this should work, but you should probably wait till Brian responds,
he always comes with the best solutions!

1 Like

He does? News to me. :stuck_out_tongue:

Let’s take the maxLevel to the next level…

In Progression.cs (Corrected from version typed via Senior Moment)

        public int MaxLevel(CharacterClass characterClass)
        {
            BuildLookup();
            if (!lookupTable.ContainsKey(characterClass)) return -1;
            if (!lookupTable[characterClass].ContainsKey(Stat.ExperienceToLevelUp)) return -1;
            return lookupTable[characterClass][Stat.ExperienceToLevelUp].Length;
        }

Now in UpdateLevel()

if(currentLevel.value>=progression.MaxLevel()) return;
1 Like

Hi, Thank you.
I tried implementing this solution and it didn’t work for me, but I got an idea based on that. I think my problem is from somewhere else, I just have to modify some things from your recommended fix and my code.

can I just know what these lines mean? I’m new to programming and sometimes get confused about what is happening.

  • if(!progression.ContainsKey(characterClass) return -1;
  • if(!progression[characterClass].ContainsKey(Stat.ExperienceNeeded)) return -1;
  • return progression[characterClass][Stat.ExperienceNeeded].Length;

Thanks.

I actually made a bit of an error, as I typed this out on the fly from memory (and us old fogeys sometimes have faulty memories)…
The correct version is this:

        public int MaxLevel(CharacterClass characterClass)
        {
            BuildLookup();
            //First check to make sure characterClass exists
            if (!lookupTable.ContainsKey(characterClass)) return -1;
            // Then look to ensure that the characterClass can level up
            if (!lookupTable[characterClass].ContainsKey(Stat.ExperienceToLevelUp)) return -1;
            // Finally, return the length of the array of values, which will be the max level.
            return lookupTable[characterClass][Stat.ExperienceToLevelUp].Length;
        }
1 Like

Got it, Thank you. I tested everything and it’s working great. :ok_hand:

Sorry about the mixup on that. Glad you got that working. I’m going to add my Brians Tips and Tricks tag to this, as it’s one of those things that should generally be implemented. Without calculating stats procedurally, by definition you need a level cap.

1 Like

I’m gonna track this tag. Brians Tips and Tricks
Thank you.

2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms