Right, levelling
by far the most common progression in every game
i am quite original, so i am also adding levels to my game
along with whispers (rebirth but with an edgy name)
now, let’s say;
each level has a 500 xp gap (500 → 1000 → 1500 → and so on)
so instead of having something like a module script that would be this:
local module = {
Level1 = 500,
Level2 = 1000,
Level3 = 1500,
-- and so on
}
return module
how would i calculate the xp required for the next level, say, level 43?
wait just a second
the 500 xp gap is just an example,
in practice i don’t know what i’ll be using, whether it’s 1000xp or 1500xp, or any different values
so i’d appreciate it if you took those into account aswell
Instead of using a module, try setting one value equal to 500, and since I’m noticing a pattern that each one is just adding 500, you get the level number and multiply that by the set value.
Here’s an example:
local levelValue = 500
local levelNumber = 5 -- setting this as 5 for an example, change this to be the level number of the stage
local xpPerLevel = levelValue * levelNumber
If you do not want to do this, you could try setting a normal level increase, and having custom level increases for specific levels.
local levelnumber = 5 -- level number duh
local levelValue = 500
local xpPerLevel
if levelnumber == 6 then -- custom level xp logic
xpPerLevel = levelValue * 15 -- custom number
else
xpPerLevel = levelValue * levelnumber -- default level calucation
end
There isn’t a way to make tables without making one for each level, but here is a much better much more optimized way of doing things, Hope I helped!
local exp_increment = 500
local function GetEXPWithCurve(level_index, modifier)
return level_index*exp_increment*modifier
end
local function GetEXP(level_index)
return level_index*exp_increment
end
These functions should work. If you want the exp gap to widen for higher levels, you can use a modifier like 1.01 , and it’ll scale.