Results 1 to 8 of 8

Thread: Programming - Mat

  1. #1
    Join Date
    May 2008
    Posts
    248

    Programming - Mat

    I played with a "xp/level" system in php.

    I would like to increase the number of XP to be used by 50 for each level.

    My formula is as follows:
    Code:
    if($exp>($level*50)+($level*200)) {
    $level = $level+1;
    )
    And I need it to level 1 by using 250 exp to rise. But from 2 to 3 will also use 250, etc., etc.

    The idea is that from 2 to 3 you should use 300, etc.

    Does anyone know how on earth I will make such a formula?

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Programming - Mat

    I have read 5 times what you wrote and I still do not quite understand what it is you want

  3. #3
    Join Date
    May 2008
    Posts
    248

    Re: Programming - Mat

    haha, it is too hard to explain .. hmm ..

    So, from level 1 to level 2 in this game, you need 200 XP.
    From level 2 to level 3, then use the 250 XP.
    3-4: 300 XP

    etc..

    So 50 more per level you say, so it finally ends up to be a lot of xp per level ..

    Helped it?

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Programming - Mat

    Code:
    $level = 1; 
    $xp = 0; 
    
    If($xp >= ($level*50)+150)
    ( 
    $level = $level+1
    )
    Edit: Did a bit fast. $ needed_xp would not have helped.

    And no it is not 200, if we are to start at 200 and stepped 50 up every time.

    If this is not what you need, I still didnt understand what you want.

  5. #5
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Programming - Mat

    Quote Originally Posted by kelfro View Post
    Code:
    $level = 1; 
    $xp = 0; 
    
    If($xp >= ($level*50)+150)
    ( 
    $level = $level+1
    )
    Edit: Did a bit fast. $ needed_xp would not have helped.

    And no it is not 200, if we are to start at 200 and stepped 50 up every time.

    If this is not what you need, I still didnt understand what you want.
    You can not compare with $ needed_xp because it has no value, you should compare with $ xp, and it's proven 200 instead of 150.

  6. #6
    Join Date
    May 2008
    Posts
    2,297

    Re: Programming - Mat

    Try the following:
    Code:
    //Do the following when you declare other variables. 
    $ current_xp = 226 // default value 
    $ xp_base_value = 200 // XP needed for next level 
    $ increment_modifier = 50; 
    
    //Call when the current xp be updated 
    //Example: updateCurrentXP(25) 
    function updateCurrentXP($gain) {
    $current_xp = $current_xp + $gain;
    }
    
    //Call just before checking the level 
    //Example: $needed_xp = getNeededXp() 
    function getNeededXp() {
    return ($xp_base_value + ($level * $increment_modifier));
    }
    
    //We get 25 XP so current_xp reach 251, and thus qualify for increase 
    updateCurrentXP(25); 
    
    //Perform check and increasing level if we are qualified 
    if ($current_xp >= getNeededXp()) {
    $level = $level + 1;
    }
    In order not to have a flat increase (ie, 50 extra xp for each level) you can make the following small addition

    Code:
    function getNeededXp() {
    $modifier = $xp_base_value + ($level * $increment_modifier) * 0.93;
    return ($xp_base_value + ($level * $increment_modifier) + $modifier);
    }
    Here, then instead of 50 extra each level, be an increase in the number of necessary xp .. namely, the higher level, the more xp needed ..

    0.93 in the example above, of course adjusted and will probably be adjusted until it feels right.

  7. #7
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Programming - Mat

    An alternative explanation might be:

    Let us look at your first example:
    $exp>($level*50)+($level*200)

    It can be reduced to:
    $exp > $level*250
    As you've noticed it a linear increase of 250 for each level.

    What you want is a exponential increase. That you must have multiplied by $ level more than once on the right side.

    Eg.
    $exp > $level*250 * $level

    Which provides:
    Level 1-2 requires 250 (250 to grow)
    Level 2-3 requires 1000 (750 to grow)
    Level 3-4 requires 2250 (1250 to grow)
    etc.

  8. #8
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Programming - Mat

    You can use heltalsdivision to make those 'steps' on 50xp

    $level = ($xp - 150) / 50;

    (there is a little crunch with the formula until it rounds 150xp that function returns a negative level)

    edit: never mind, not the revised questions

Similar Threads

  1. What does CVS mean in programming?
    By Gajananvihari in forum Software Development
    Replies: 5
    Last Post: 12-03-2010, 05:09 PM
  2. What does DOM mean in programming?
    By Gadin in forum Software Development
    Replies: 5
    Last Post: 11-03-2010, 05:33 PM
  3. Xml with C# in .NET programming
    By Remedy in forum Software Development
    Replies: 4
    Last Post: 03-03-2010, 08:10 PM
  4. Socket programming: Is any new Programming Language?
    By Kushan in forum Software Development
    Replies: 3
    Last Post: 14-11-2009, 11:13 AM
  5. Replies: 3
    Last Post: 13-12-2008, 01:49 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,710,821,412.43013 seconds with 16 queries