ID:865762
 
mob
proc/Level()
while(src.XP >= src.MXP)
var/remainder = src.XP - src.MXP
src << "<center><b> You have leveled up to level [lvl]</center>\n\n\n\n"
src.lvl += 1
src.XP += remainder


I noticed that too many games / resources use the if() proc for levelchecking. This can work, but you have to do so many work-arounds to level more than once. If you use the while() proc, there's no need to loop your Level() proc just because you gained 1000 XP when your maximum is 10.

You're not handling the remainder correctly. You should be setting the XP to the remainder, not adding to it. Although, a simple src.XP -= src.MXP is more straight-forward, I think.

Also, you need to display the level-up message after increasing the level (or it shows the wrong level).
mob/proc/level_up()
if(exp >= max_exp)
level += 1
// Set their exp to the remainder
exp = exp - max_exp
// Now call level_up() one more time.
// calling this will level you up again if you need to.
level_up()


That's what I do instead.
In response to DarkCampainger
DarkCampainger wrote:
You're not handling the remainder correctly. You should be setting the XP to the remainder, not adding to it. Although, a simple src.XP -= src.MXP is more straight-forward, I think.

Also, you need to display the level-up message after increasing the level (or it shows the wrong level).
I'm sorry, this code was for a game I'm working on, I accidentally left out a few things that are essential.

mob
proc/Level()
while(src.XP >= src.MXP)
var/remainder = src.XP - src.MXP
src.lvl += 1
src << "<center><b> You have leveled up to level [lvl]</center>\n\n\n\n"
src.MXP += 20
src.XP = 0
src.MHP += rand(5,10)
src.HP = MHP
src.XP += remainder

In response to BeignetLover
BeignetLover wrote:
> mob
> proc/Level()
> while(src.XP >= src.MXP)
> var/remainder = src.XP - src.MXP
> src.lvl += 1
> src << "<center><b> You have leveled up to level [lvl]</center>\n\n\n\n"
> src.MXP += 20
> src.XP = 0
> src.MHP += rand(5,10)
> src.HP = MHP
> src.XP += remainder
>


If your trying to have them level until they have less XP than their MXP value wouldnt you set XP to the remainder? A flow chart of what im currently thinking that snippit will do is this -

Base variables:
XP = 150
MXP = 100
----
Chart:
Level() is called.
src.XP is higher than src.MXP
remainder = src.XP - src.MXP = 150 - 100 = 50||remainder = 50
src.level + 1
Level msg
src.MXP += 20 = 120||src.MXP = 120
src.XP = 0
HP/MHP handling
src.XP += remainder = 50||src.XP = remainder.
------------------------------

When changing the programming to -
mob
proc/Level()
while(src.XP >= src.MXP)
var/remainder = src.XP - src.MXP
src.lvl ++
src << "You leveled up!"
//All MHP/HP handling
src.MXP += 20
src.XP = remainder

- Youll have more efficent run-times and less un-needed variable handling. Making things even more efficent you could get rid of the remainder variable all together and just use the "-=" statement to subtract src.MXP from src.XP.

Just my two cents.
In response to D-Cire
*cough*
mob/proc/level_up()
if(exp >= max_exp)
level += 1
// Set their exp to the remainder
exp = exp - max_exp
// Now call level_up() one more time.
// calling this will level you up again if you need to.
level_up()


Lol. Does the exact same thing as your snippet does with one less line ;) (I'm disregarding your output message and MXP += 20 lines).

EDIT: Also, his way will still work, sort of.
Setting the XP to 0 and then adding the remainder is the same thing as setting the XP to the remainder. He's just wasting more space his way.
In response to Albro1
Being honest upon first glance i didn't notice he set src.XP to 0 in that snippet since he didn't in the original. Upon revisiting it i noticed and revised what i was typing.
Or, you know, you can do it the right way and utilize OOP

http://www.byond.com/forum/?post=35530
This is OT, but randomly increasing the player's HP and MP is bad game design for a number of reasons
In response to Cloud Magic
You do realize the following:
A) There is no "right way" to do it at all. It comes down to what the user is most comfortable with, if it works, and the down/upsides to doing it said way. Three people have posted three different way that work fine already in this thread.

B) The link you posted is for datum-specific things for the most part. This thread is about a simple level-up procedure and advice on how to do so.

So, next time you try to act smart, i suggest reading and being less ignorant in your post.

@Yut - Id honestly love to hear those reasons. Mind posting them or paging me them? Im not very good at Game Design and am looking for ways to increase performance.
In response to D-Cire
I actually was acting smart. My way was better than yours and Albro1's because it uses proper programming practices and is efficient. Is that what you wanted me to say? Because your comment of me being 'ignorant' sure as hell got it out of me.
In response to Cloud Magic
I wanted you to specify that there is no "right" way. Which you just did. Aside from that - this was a simple thread for advice on using a while loop for a level check proc instead of an if statement. We gave him c&c on his own programming, you simply went out of your way to act arrogant.
In response to Cloud Magic
Object-oriented programming is fine and dandy, and in most cases is the better way to go. With something as simple as experience, it's really a matter of personal preference. You can either define some variables and manipulate them, or define one object variable so you can access and define that object's variables.
Well, generally(especially in action games) randomness is the enemy of skill. This makes clear sense on the surface. That's why things like items, for example, are not preferred in super smash bros.

On top of that, it totally smashes the balance by randomly giving some users a benefit over others based on random stats. It makes much more sense to do max hp += 7 as opposed to max hp += rand(5,10)
mob
proc
Check_Exp()
if(src.exp<src.expmax) return
else
var/lvls=0
while(src.exp>=src.expmax)
lvls+=1
src.exp-=src.expmax
src.Level_Up(lvls)
Level_Up(N as num) //level N amount of times
if(!N) return
src.level+=(1*N)
src.skillpoints+=(3*N)
src.statpoints+=(1*N)
src.hpmax=(80+((10*src.level)+(10*usr.vit)))
src.hp=src.hpmax
src.expmax=100*(src.level*10)
src<<"<i><font color=white>You've leveled up!<center>***You're now level [src.level]***</center>"


I've been using this for some time, works great for me.

[EDIT]
I use this method so I can give levels as a quest reward, say someone completes a major questline, they'd be due multiple levels. It's easier- and simpler to give them the levels and not give them exp then check the exp.
[END EDIT]
In response to NNAAAAHH
I do hope that those spaces are a result of you typing this in the website and that you don't use spaces for indentation in your code.
In response to Albro1
I made a slight alteration in the web browser, which doesn't allow for tabs. So yes.