Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Viewing all articles
Browse latest Browse all 4666

Formula for calculating user experience

$
0
0

I would like (without using a gem) to create a level and experience point system for my users.

When creating his account, he starts level 0 with 0 experience points. To reach level 1 he will need 10 additional points, for a total of 10 points. For level 3 he will need 30 additional points, for a total of 60 experience points. Each additional level requires 10 more experience points. (see example below).

Level  |  Total XP  |  XP for next level|----------------------------------------|0      |    0       |    10             |1      |    10      |    20             |               2      |    30      |    30             |3      |    60      |    40             |4      |    100     |    50             |5      |    150     |    60             |etc...

I would like an xp column in my user table that would represent the total experience of a user.

In my view I would like to display its level. But what is the formula for calculating this?

Let's imagine that my user has 157 experience points in total. Which corresponds to a level 5. How to calculate a level only via the total experience points and how to calculate this regardless of its total experience point whether it is 38 like 369 or 4393.


Viewing all articles
Browse latest Browse all 4666

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>