Infinity% showing when hitting last level index in progression for player

I’m running into a weird bug where the display for health is showing infinity% when the player has reached the “max level”, i.e the last level index in the progression object. The character can still die so it clearly has a health amount and after death, the health display says NaN%. I’m lost on why the health display is displaying this though. Any thoughts?

The issue here is that once it reaches the last level, the way the code is written, we’re returning 0… this is causing a division by zero when you GetHealthAsPercentage (NaN = division by zero).

If, in progression, you returned the value of the last element of the array instead of 0, this would fix the problem.

See, that’s what I thought line 27 was doing. Am i misunderstanding?


This seems to fix it but then it skips the second to last level.

public float GetStat(Stat stat, CharacterClass characterclass, int level)
{
     BuildLookup();
     float[] levels = LookupTable[characterClass][stat];
     if(levels.Length < level)
     {
          return levels[levels.Length-1]; //return the last entry
      }
      return Levels[level-1];
}
1 Like

This did it. Thank you

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