# Help solving for x in exponential formula

This topic is 561 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm working on an exponential formula for my experience progression.  Check out the sheet and graph here:

exp = ROUNDDOWN(600 + (x ^ 4.75)), exp is amount of experience, x is any level between 1 and 100.

My characters store only how much experience they have, so I need a function that plugs exp into the formula and solves for x to convert experience points to a floored level

From what I've gathered Logarithm is useful here, but I'm struggling to figure it out as my math skills aren't that great.

##### Share on other sites
exp = ROUNDDOWN(600 + (x ^ 4.75)), exp is amount of experience, x is any level between 1 and 100.

The easiest way to do this is to invert the exponent.

x = ROUNDDOWN( exp ^ ( 1 / 4.75 ) ) - 600

Edited by missionctrl

##### Share on other sites

Also, I'm not one to judge your game design, but is there a good reason you are using such large numbers?  I bring this up because you're generating numbers that are well beyond the maximum size for a standard integer variable, which is a little over 2 billion.

##### Share on other sites
Another approach I've seen used in games: instead of having a single pair of functions, we just have a lookup table instead. I.e.:

Level 1 = 100xp
Level 2 = 300xp
Level 3 = 600xp
...
Level 100 = 1,000,000xp

So if you have some number of XP, you find the highest entry in the table where entry.xp <= player.xp.

The advantage is that you can change your level curve arbitrarily instead of trying to find the inverse of some (potentially very) complicated equation. For example, you could make levels 1-60 go quickly, then have a sudden slowdown from level 61 to 100.

The disadvantage is that if you only store XP in a variable and calculate level on the fly every time, it means doing a binary search every time you use it. If this becomes a problem I definitely suggest caching the Level value as well. Edited by Nypyren

##### Share on other sites

exp = ROUNDDOWN(600 + (x ^ 4.75)), exp is amount of experience, x is any level between 1 and 100.

The easiest way to do this is to invert the exponent.

x = ROUNDDOWN( exp ^ ( 1 / 4.75 ) ) - 600

Looks easy enough, thanks!

I don't see an exponential formula here (ie  n^x, where n is a number). See also

https://en.wikipedia.org/wiki/Exponential_function

https://en.wikipedia.org/wiki/Power_function

Inverse of power function is to take to the 1/n power: y = x^n -> x = y^(1/n).

Thanks for the correction.  I will find the time to read these articles, I'm really lacking in the math department :)

Also, I'm not one to judge your game design, but is there a good reason you are using such large numbers?  I bring this up because you're generating numbers that are well beyond the maximum size for a standard integer variable, which is a little over 2 billion.

That's a good point.  I'm following the design of other games who reach 3 billion+ experience for maximum level, so I suppose the long data type would be needed.  I might just lower my numbers to fit in an int and make up for it elsewhere, but it's all really early stages still :)

Another approach I've seen used in games: instead of having a single pair of functions, we just have a lookup table instead. I.e.:

Level 1 = 100xp
Level 2 = 300xp
Level 3 = 600xp
...
Level 100 = 1,000,000xp

So if you have some number of XP, you find the highest entry in the table where entry.xp <= player.xp.

The advantage is that you can change your level curve arbitrarily instead of trying to find the inverse of some (potentially very) complicated equation. For example, you could make levels 1-60 go quickly, then have a sudden slowdown from level 61 to 100.

The disadvantage is that if you only store XP in a variable and calculate level on the fly every time, it means doing a binary search every time you use it. If this becomes a problem I definitely suggest caching the Level value as well.

I'll keep this in mind in case the formula based experience progression doesn't turn out!

Edited by Crayz92

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
5. 5
A4L
11

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633768
• Total Posts
3013744
×