# level up 6 times with 40 EXP!?!?!?!

Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last
• 03-02-2003
Blizzarddog
level up 6 times with 40 EXP!?!?!?!
Okay, i have the preset needs to level up in my text game. But when i battle, i get out of the battle, i have 40 exp points, and i level up to level six when i need 110 points to do so... is there an easy and trusty way to make ma rpg level up system?
• 03-02-2003
Yawgmoth
• 03-02-2003
Blizzarddog
well, uh.. i kinda deleted that part. But heres an example of what it looks like, trimmed of course.
Code:

```int pexp = 0; //Player Exp. int plevel; //player level lu1 = 10; //level up 1 lu2 = 30; lu3 = 50; int main() { if (pexp >= lu1) { plevel++; } }```
• 03-02-2003
-=SoKrA=-
You should check backwards for the level. I mean, check first for level 5, then level 4, level 3...
With the code you have, it'll add 1 to your level count even if the player is already in or above that level. You could also check for the level s/he's in. It'll be useful to work with absolute values rather than relative. What I mean is: if the player has enough exp points to go to level 1, make the level 1, instead of adding one, which could also solve the problem.
Just a few suggestions.
• 03-02-2003
Blizzarddog
Code:

```if (pexp => lu5) { cout << "Level 5!\n"; plevel = 5; }```
and worked my way down the chain from that.
It still did the same stuff.
• 03-02-2003
Magos
I'd suggest you make an algorithm for the experience needed, or at least make a table for them instead of lots of hardcoded if-statements.

Assume you gain a level for 6 exp, the the amount required doubles for each level (6, 12, 24, 48, 96 etc...):
Code:

```int CurrentExp = 0; int ExpForNextLevel = 6; int CurrentLevel = 1; void CheckForLevelUp() {   //Loop several times in case you gain enough experience for multiple levels   while(CurrentExp >= ExpForNextLevel)   {       //Increase stats like Strength and Health here       ...       //Increase the level       CurrentLevel++;       //Set the exp for the next level, in this case double it       ExpForNextLevel *= 2;   } }```
• 03-02-2003
Blizzarddog
I use rand() for the damage. How could i use that with the levels?
• 03-02-2003
Magos
Quote:

Originally posted by Blizzarddog
I use rand() for the damage. How could i use that with the levels?
Have a base damage and a variable damage counter, which you increase on levelup. Then calculate the damage from:
Code:

`BaseDamage + (rand() % VariableDamage)`
The damage will then range from BaseDamage to BaseDamage + VariableDamage - 1, thus be increased by each level.
• 03-02-2003
jverkoey
Quote:

Originally posted by Blizzarddog
well, uh.. i kinda deleted that part. But heres an example of what it looks like, trimmed of course.
Code:

```int pexp = 0; //Player Exp. int plevel; //player level lu1 = 10; //level up 1 lu2 = 30; lu3 = 50; int main() { if (pexp >= lu1) { plevel++; } }```

ok blizzard, if you want a "decent" level up system, you should have something like this:

Code:

```#define NUMLEVELS  99    // This is the max amount of levels the character can get int levelExp[NUMLEVELS]; //Create a huge table of all the exp int pExp;  //player's exp int pLevel;  //player's level void testLevelUp(); void initAll(); int main() {       initAll();  //Initialize all of the variables       //  ^^ that code should be placed at the very top, outside of the game loop, because it sets up the default settings for each variable     //  Here would go any other setting up     while(1)  // Just making an infinite loop because I don't feel like making an entire engine, lol     {           // Now, what you want to do here is, before you go trying to test the users exp EVERY loop, only test it at the end of a battle or whatever you're using for your game           testLevelUp();  //Test if you leveled up     } } void initAll() {     int b=10;     for(int a=0;a<NUMLEVELS;a++)     {         levelExp[a] = b;         b+=6;     } //explanation of above ^^ code: // // This code will run through all of the levels, in this case 99 // and set up their default values // then, you store b to the levelExp slot for the current level being // edited, and that'll make your list of level exp's you need // also, you need to increment the b value, otherwise it'll just keep // making all of the values equal 10 // you may want to add something like: // b+=rand()%10+5; // instead of  b+=6, and if you don't want it to be different every // time, DON'T seed it, or seed it with the same thing every time // that way it will be a little more interesting //     pExp=0;     pLevel=0; } void testLevelUp() {   if(pExp>levelExp[pLevel])  //test if the player's current exp is greater than the current level's required exp       pLevel++; }```
wow, lol, I just made all of that up off the top of my head in 10 minutes, lol, I should start making dos games again, i forgot how simple they were

well, I hope that that helps you, and anyone else who has this problem

oh, and if i didn't say earlier, the problem with your code was that you were testing if your exp was greater than level 1's requiered exp value, then add the level, therefor, say....

if you have 53 experience
and you need 20 for level 1, 36 for level 2, 57 for level 3
and you do your version of the testing, you'll level up to level 2

see what I mean? if not, just reply here again or pm me

-edit-
oh, i just noticed magos' post, he kinda mentioned the same thing, but with this one, you can actually have a lookup table of everything, and if you want it to double in exp every time like his does, just make b*=2;
• 03-03-2003
Blizzarddog
It still won't level up!
Well, it might, its just that, when i have 1090 exp, it would level out of level 1, dontcha think?
• 03-03-2003
LouDu
blizard u ask alot of questions, i also do, but please read before you post the same simple things over and over agian, i do ask alot of questions, but i research on them before i ask
• 03-03-2003
jverkoey
Quote:

Originally posted by Blizzarddog
It still won't level up!
Well, it might, its just that, when i have 1090 exp, it would level out of level 1, dontcha think?

i don't seem to understand what you mean, if you mean, it'll only level out of each level once, and not go up to the next one with the exp, then you just do a loop, like so:

Code:

``` while(pLevel<NUMLEVELS) {   if(pExp>levelExp[pLevel])       pLevel++;   else       break; }```
and that will run through all of the possible levels you can go up, until you've reached a point where you can't level up anymore

-edit-
fixed a typo
• 03-05-2003
Blizzarddog
And loudu, I was in the middle of typing the question when the others replied. Thats why i ask the questions when they're answered
• 03-05-2003
Blizzarddog
And loudu, I was in the middle of typing the question when the others replied. Thats why i ask the questions when they're answered
• 03-05-2003
Yawgmoth
Don't double post!!!
Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last