Should we really recalculate the level every time?

I’m sort of skeptical about recalculating the level every time we check it, particularly considering how many times we check for the player’s level, and for how many different reasons (sometimes even every frame).
Wouldn’t it be better and more performant to task Experience to check if the level is increased whenever we add some to the total? That happens far less frequently, and I can’t think of any non-design-time situation when the level changes but Experience remains the same.

If I go down this route, is there any future part of the course which will clash with this solution?

I actually do something like this in my personal projects:

First, I make BaseStats an ISaveable, and return/restore the level.
Then I have an event in Experience

public event OnExperienceGained;

Then only when OnExperienceGained is fired, I calculate the level.

I also have my ExperienceNeededToLevel represent the experience for that level only, and when the character levels, I instruct Experience to deduct ExperienceNeededToLevel.

3 Likes

This is what I was thinking, more or less (although I’ll admit that using an event to decouple Experience from BaseStats is clever and I wasn’t thinking about that)

Thanks!

Privacy & Terms