# Visual Basic > Games and Graphics Programming > Game Demos >  [.Net 2010]Rpg Game Help - Leveling

## Odin the Wise

Hello! I'm new to the forum so if I posted this incorrectly, I apologize beforehand. I am building an RPG game in Visual Basic .Net 2010, and everything is going great so far! No errors or mishaps, but what I've come to ask about is when I go to level my player up, I want to use the best method possible. I don't know any common algorithms used for such purposes and I would apreciate some input! Please and thank you! 

P.S: I'm currently using this - my.settings.expMax = playerExperience.maximum + (my.settings.expMax  my.settings.playerLevel) / 2

It works, but eventually the exp is really really high. Starts at 100 and lvl 3 is 1350

----------


## Niya

Why not use a simple scheme like 100 for level 1 200 for level 2 and so on ?

----------


## Odin the Wise

Because its too generic. I want something a little more complex. Plus, there are modifiers for EXP, so when the player reaches a certain level in Intelligence, The modifier will change to make it easier to level up.

This is the actual code for Changing the MaxEXP on Leveling Up:
        My.Settings.MaxEXP = My.Settings.MaxEXP * (My.Settings.expMultiplier * My.Settings.playerLevel) / 2
The multiplier is now 3

----------


## Odin the Wise

> Because its too generic. I want something a little more complex. Plus, there are modifiers for EXP, so when the player reaches a certain level in Intelligence, The modifier will change to make it easier to level up.
> 
> This is the actual code for Changing the MaxEXP on Leveling Up:
>         My.Settings.MaxEXP = My.Settings.MaxEXP * (My.Settings.expMultiplier * My.Settings.playerLevel) / 2
> The multiplier is now 3


So Basically at Level 1 you have 100 EXP, Then 300, then 1350, and Level 5 has 6870

Thats extremely exponential. I would like Level 1 to be 100 and level 100(Cap) to be 1,000,000 with an exponential growth rate, not linear. So level 50 would have to be less than 500,000, say like 300,000 or so. 

What would be the Math for this?

EDIT
====

Not TOO exponential, as you can see, or I wouldn't be posting here :3

----------


## passel

I guess something close to what you want would be
EXP = 100 * (level ^ 2)

That gives you 100 at level 1, 1000000 at level 100, and 250000 at level 50.

----------


## Odin the Wise

> I guess something close to what you want would be
> EXP = 100 * (level ^ 2)
> 
> That gives you 100 at level 1, 1000000 at level 100, and 250000 at level 50.


That sounds like a good one, I'll check it out in a minute.

Another issue is EXP overflow. If I kill an enemy for 50exp but I only need 25exp, how would I get it to add the remaining 25exp to the next level?

And when it comes to the EXP modifier, I'll just use it with enemyExp to change how much EXP is given based on player Intelligence :3

Edit:
Works great, thanks! 1M may seem a little high tho. Idk. I'll leave it for now... Thanks a lot man! Now I just need to fix EXP OverFlow

----------


## passel

Well, if you would rather go 100 to 100000, then you can change the exponent to 1.5, but you will get level values that have many digits after the decimal point quite often. You probably want to round up to next even 100, so could do this.


```
  Dim LevelMax as Double 
  LevelMax = Int(100 * (level ^ 1.5)) + 99  'add 99 to force a roundup to 100, when truncating in the next line
  LevelMax = d - d Mod 100  'round down to the previous 100
```

I'm not sure what the issue is with EXP OverFlow.
If the EXP would exceed LevelMax, then  set some variable to the overflow amount and add it to the EXP when you reach the next level.

----------


## Odin the Wise

Thanks alot, I'll keep that in mind. I came up with a simple OverFlow Function that catches when settings.currentExp is Greaterthan maxExp, and it works, except when it doesnt set the current exp to 0 then add the overflow, it just changes the max Exp, keeps the current exp the same, and adds the over flow, Like so:

Intitial: Exp = 0; Max Exp = 100
+101 Exp

^LEVEL UP^

Post-Level: Exp = 101 Max Exp = 400

heres the Leveling.vb Code:


```
Public Class Leveling
    Inherits frmMain

    Public Sub expOverFlow()
        Dim overflow = My.Settings.expOverFlow
        overflow = 0
        If My.Settings.currentEXP >= My.Settings.MaxEXP Then
            overflow = My.Settings.currentEXP - My.Settings.MaxEXP
            My.Settings.currentEXP = 0
            My.Settings.Save()
            My.Settings.Reload()
            My.Settings.currentEXP = My.Settings.currentEXP + overflow
            My.Settings.Save()
            My.Settings.Reload()
            LevelUp()
        Else
            LevelUp()
        End If
    End Sub

    Public Sub LevelUp()
        My.Settings.playerLevel = My.Settings.playerLevel + 1
        My.Settings.MaxEXP = 100 * (My.Settings.playerLevel ^ 2)
        'My.Settings.expIncrement = My.Settings.expIncrement * 2
        My.Settings.Save()
        My.Settings.Reload()
    End Sub
End Class
```

----------


## Odin the Wise

Ok, so I'm sure what I did, but I made it worse D:

I have button, and a NumbericUpDown
The button just adds the NumericUpDown's value to currentExp.
But when I go to test it. Anything over 1 Exp crashes the game, and tells me "-98 is not a valid Value for ProgressBar" (Paraphrased)
So I add 1 Exp, works fine, add 1 more for a whopping total of 2 Exp and it crashes with said error.
I deleted all the functions that call for LevelUp() and just made it with the button.

Also merged expOverFlow and LevelUp, like so:



```
Public Class Leveling
    Inherits frmMain

    Public Sub LevelUp()
        Dim overflow = My.Settings.expOverFlow
        Dim exp = My.Settings.currentEXP
        Try
            If My.Settings.currentEXP >= My.Settings.MaxEXP Then
                overflow = exp - My.Settings.MaxEXP
                My.Settings.currentEXP = 0
                'My.Settings.Save()
                'My.Settings.Reload()
                My.Settings.playerLevel = My.Settings.playerLevel + 1
                My.Settings.MaxEXP = 100 * (My.Settings.playerLevel ^ 2)

                'If Experienced earned during LevelUp overflows, Handle it
                My.Settings.currentEXP = My.Settings.currentEXP + overflow

                'Save any changes made
                My.Settings.Save()
                My.Settings.Reload()
            End If
        Catch ex As Exception

        End Try
    End Sub
End Class
```


This is very frustrating  :Mad:

----------


## Odin the Wise

BOOM BABY! Fixed that bullcrap! Thanks for your help. Is it OK if I leave this thread open incase I run into another problem(as long as it deals with Leveling as the thread name implies?)

----------

