Thread: level up 6 times with 40 EXP!?!?!?!

  1. #1
    Linux Forever
    Join Date
    Oct 2002
    Posts
    373

    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?
    This war, like the next war, is a war to end war.

  2. #2
    ! |-| /-\ +3 1337 Yawgmoth's Avatar
    Join Date
    Dec 2002
    Posts
    187
    Maybe you should post some of your code so we can help you find the bug in your program.
    L33t sp3@k sux0rz (uZ it t@k3s 10 m1|\|ut3s 2 tr@nzl@te 1 \/\/0rd & th3n j00 h@\/3 2 g3t p@$t d@ m1zpelli|\|gz, @tr0(i0u$ gr@mm@r @|\|d 1n(0/\/\pr3#3|\|$1bl3 $l@|\|g. 1t p\/\/33nz j00!!

    Speling is my faverit sujekt

    I am a signature virus. Add me to your signature so that I may multiply.

  3. #3
    Linux Forever
    Join Date
    Oct 2002
    Posts
    373
    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++;
    }
    }
    This war, like the next war, is a war to end war.

  4. #4
    Me -=SoKrA=-'s Avatar
    Join Date
    Oct 2002
    Location
    Europe
    Posts
    448
    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.
    SoKrA-BTS "Judge not the program I made, but the one I've yet to code"
    I say what I say, I mean what I mean.
    IDE: emacs + make + gcc and proud of it.

  5. #5
    Linux Forever
    Join Date
    Oct 2002
    Posts
    373
    I had code like
    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.
    This war, like the next war, is a war to end war.

  6. #6
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    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;
       }
    }
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  7. #7
    Linux Forever
    Join Date
    Oct 2002
    Posts
    373
    I use rand() for the damage. How could i use that with the levels?
    This war, like the next war, is a war to end war.

  8. #8
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    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.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  9. #9
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    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;
    Last edited by jverkoey; 03-02-2003 at 11:12 PM.

  10. #10
    Linux Forever
    Join Date
    Oct 2002
    Posts
    373
    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?
    This war, like the next war, is a war to end war.

  11. #11
    |<o>| <--cyclopse LouDu's Avatar
    Join Date
    Mar 2003
    Posts
    137
    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
    Languages <> C++, HTML

    /*The Ledgend of Ludlow Coming to a PC Near
    You intro Cinenmatic Needed email me of
    Reply to one of my threads if you can make
    one, thats decent. */

  12. #12
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    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

  13. #13
    Linux Forever
    Join Date
    Oct 2002
    Posts
    373
    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
    This war, like the next war, is a war to end war.

  14. #14
    Linux Forever
    Join Date
    Oct 2002
    Posts
    373
    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
    This war, like the next war, is a war to end war.

  15. #15
    ! |-| /-\ +3 1337 Yawgmoth's Avatar
    Join Date
    Dec 2002
    Posts
    187
    Don't double post!!!
    L33t sp3@k sux0rz (uZ it t@k3s 10 m1|\|ut3s 2 tr@nzl@te 1 \/\/0rd & th3n j00 h@\/3 2 g3t p@$t d@ m1zpelli|\|gz, @tr0(i0u$ gr@mm@r @|\|d 1n(0/\/\pr3#3|\|$1bl3 $l@|\|g. 1t p\/\/33nz j00!!

    Speling is my faverit sujekt

    I am a signature virus. Add me to your signature so that I may multiply.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Monitoring soundcard line-out level
    By moose in forum C Programming
    Replies: 4
    Last Post: 04-10-2009, 05:46 PM
  2. Diablo's random level generation
    By glo in forum Game Programming
    Replies: 7
    Last Post: 07-19-2008, 03:04 AM
  3. Listing binary tree numbers by level
    By Nazgulled in forum C Programming
    Replies: 5
    Last Post: 06-16-2008, 10:36 AM
  4. C/C++, low or high level?
    By Sentral in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 01-23-2007, 11:43 PM
  5. Header Files and Classes.
    By Lithorien in forum C++ Programming
    Replies: 10
    Last Post: 08-13-2004, 12:10 PM