Efficient system for calculating levels earned for massive amounts of experience?

Hey developers,

I’m planning out a system for an exponential leveling-like system.

The concept is pretty much the same as any other, however the experience a player can obtain is very MASSIVE compared to the level requirements. The issue arises where a player levels up hundreds of times. I’m clueless to how a developer would support mass leveling up without thousands of calculations.

My initial implementation was a loop, this won’t hold for too long.

My current equation for experience required is (x^2) + 10, where x stands for the current Level I’m calculating the experience for.

A very possible scenario would be a player at level 1 obtaining 1,000,000,000,000 in experience. I need to calculate how many levels the player would obtain as a remainder of that quadrillion, and with my current method (looping), I’d have to loop the system around about 144,244 times. (Not good)

Are there any more efficient ways that you know of? My current implementation is pretty poor, and I’d love to optimize it.

I’ll answer any questions that you may have.

Have a happy Spooktober, if you celebrate it!

since it’s linear, you could math out for (1^2)+10, and divide the final experience by that, the resulting thing should be the level
(unless my brain is too tired to do math right now)

nevermind i’m a big dumb dumb

This is what I use to calculate all of my leveling functions.

math.floor((math.sqrt(((n+13)*2)/100))+0.5) -- n is equal to experience which then throws out what level you are at.

((n(n+1)) / 2)*100 --n is equal to level which outputs the experience needed for the next level```

That would work, I thought about doing something like that earlier. My only issue was with the experience value resetting when you level up. Since experience values can go really high (near the maximum limits of a NumberValue), I’d want to be able to use the entire range of the NumberValue.

The way I make experience bars is by multiplying the level by the desired amount… if the level is 1 and the experience is easy to earn then I set it to 150, that way every time the user levels up 150 turns to 300 then 450 etc…

To make it harder over time you can do something like this… (level+(level/2))*150)

I’m not looking for how I’d calculate experience for a given level. I’m trying to figure out the most efficient solution to rapidly leveling up thousands of times in a performant manner.

My current system uses a loop, and I’d need to loop my script thousands of times, one for each time I level up the player.

That shouldn’t be a problem, even if you’re going through every level to see if that’s the right one. But if you’re using a simple mathematical function to calculate the exp required for a given level, you can just use the inverse function to get the level you reach with a specific amount of exp.

If your function is

xp(level) = level^2 + 10

, then

level(xp) = sqrt(xp) - 10
2 Likes

Thanks for responding,

Inversion was one of the solutions I was looking at earlier. The only issue I had with it was that it awards experience relative to level 1.

Say I’m at level 200, and I receive 10 experience. My experience needed to level up should be at 40010, not 11. The only solution I had that lets me use inversion would be to find the sum of all the experience needed between level 1 and x, and add that into the inverse function. Loops work, but this method takes a lot of time to compute.