-1

This question may already have been asked, but, nonetheless, what would an example formula be for getting the current level from the total amount of EXP a player has? As in the variable that's known is the EXP, the one I'm trying to get from the formula is the current level.

Quadryc
  • 21
  • 1

1 Answers1

0

There isn't really a best way to do this, so I'll give you one way it could be done. Assuming you had experience represented as a number you would want to:

  • Define an experience curve you're going to want to use. Normally subsequent levels take increasing amounts of experience to reach.
  • In your game have a map data structure that maps an experience value to a given level based on your curve.
  • Find the map key closest to but not over the current experience value. Display the mapped level as your current level.


Example experience curve.

var experience_curve = {};
experience_curve['0'] = 1;
experience_curve['100'] = 2;
experience_curve['300'] = 3;
experience_curve['700'] = 4;
experience_curve['2100'] = 5;


Bonus: To display progress towards the next level.

  1. Find the map key closest to but not over the current experience value
  2. Subtract the key found in 1. from the next map key, this is how much total xp is needed for the next level.
  3. Subtract 1. from the player's current experience value, this is how much progress has been made into the next level.
  4. Divide 3. by 2. and you now have the percentage of how far you are into the level.