So I have a formula in my game that determines the minimum amount of exp for each level, which is exp = 25*1.1^(level-1). But how would I determine level based on just knowing exp, example: 250=25**(1.1 ^level). Of course I know you’d divide each side by 25 but what would I do with 25=1.1^x? How do I get x from that?
I’m a bit confused,
And
Are 2 different equations, can you clarify this a bit more
By the way, an easy (non math required) way is to just go through the levels, calculate that level’s exp and the next level’s exp then check if it is in that range, if so then that’s the level
The 1st one is to decide how much exp is needed for a level. Like if a script needed to know how much exp level 5 would take, it would be exp=25*1.1^(5-1) which is about 37 exp. The 2nd is if for example a players exp was passed to the script through an argument, it would have to decide what level that amount of exp is and I used 250 exp as an example. I did mess up slightly on that one it’s 1.1^level-1.
That’s pretty inefficient though, however I just found out math.log is for exactly this, I just didn’t know before because I’ve never worked with logarithms. I’ve encountered an annoying error which is floating point errors which are definitely gonna be a problem.
@Inqxii I agree with both things you said here, here is a demo (of the math version):
local lvl1Exp = 25*1.1^(1-1)
local lvl2Exp = 25*1.1^(2-1)
local lvl3Exp = 25*1.1^(3-1)
local lvl5Exp = 25*1.1^(5-1)
print("Lvl 1 exp:", lvl1Exp)
print("Lvl 2 exp:", lvl2Exp)
print("Lvl 3 exp:", lvl3Exp)
local lvl1 = math.floor(1 + (math.log10(lvl1Exp/25)/math.log10(1.1)))
print("Lvl:", lvl1)
local lvl2 = math.floor(1 + (math.log10(lvl2Exp/25)/math.log10(1.1)))
print("Lvl (2):", lvl2)
local lvl3 = math.floor(1 + (math.log10(lvl3Exp/25)/math.log10(1.1)))
print("Lvl (3):", lvl3)
local lvl5 = math.floor(1 + (math.log10(lvl5Exp/25)/math.log10(1.1)))
print("Lvl (5):", lvl5)
local mysteryLvl = math.floor(1 + (math.log10(250/25)/math.log10(1.1)))
print("Mystery Level:", mysteryLvl)
math.floor
is just to round numbers down
I tried that it didn’t work it would output numbers that don’t work. But I instead tried
local baseExp = 25
local getLevel = function(exp)
local newExp = exp/baseExp
local level = math.floor(math.log(newExp, 1.1))
return level
end
which works but even with the math.floor I still get numbers returned like 1.999999
If you are looking for a good exp formula here’s the one I use for my game.
function XP.GetLevelFromExp(Exp : Float?, MultiplierValue : Nil?)
return math.floor((math.sqrt(((Exp+13)*(MultiplierValue or 4))/100))+0.5) --Total exp to level up
end
function XP.GetExpFromLevel(Lvl : Float?, MultiplierValue : Nil?)
return ((Lvl*(Lvl+1))/(MultiplierValue or 4))*100 -- How much exp to reach the level
end
Though in the end it really depends what type of game it’s for. Do you need an exponential growth for exp or a constant growth. This one that I supplied is for exponential growth
I was doing it exponentially but not just squaring the level I did it the same as compounding interest which is just raising the rate of growth to the power of the level but this one would definitely work too I’ll probably use it, it’s not super important in my game
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.