SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post Need help wt Javascript

    Hello,
    I trying to create a calculator for a game, and i stuck on exp matching, i cant understand how its works .
    I managed to create code who how many exp needed to reach certain level :
    Code:
    LVL=new Array();
    LVL[1]=128;
    LVL[0]=128; 
         m=.05;
         for (i=1;i<101;i++) {
          if (i>1) {
           LVL[i]=Math.floor(LVL[i-1]+(LVL[i-1]*m)); 
           m=m+.0015;
          }
         }
    I need exp to next level and exp difference.
    Here is formula:
    +-----+---+-------+----------+
    |Level|Exp |Exp diff|Exp needed|
    +-----+---+-------+----------+
    |LVLX-|-A-|---B---|----C-----|
    +-----+---+-------+----------+
    |LVLY-|-D-|---E---|----F-----|
    +-----+---+-------+----------+

    LVLY exp needed = D-A
    LVLY exp diff = B+F

    F=D-A D-E=128
    E=B+F A-B=128
    D-E=A-B
    (levels starts from1 and till 99)
    Thanks.
    Last edited by ignas2526; Jun 25, 2008 at 16:51.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,688
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    From your calculations, it seems that the following table will match.


    +-----+-----+--------+----------+
    |Level| Exp |Exp diff|Exp needed|
    +-----+-----+--------+----------+
    |LVL0 | 128 | . 0 . .| . .1 . . |
    +-----+-----+--------+----------+
    |LVL1 | 129 | . 1 . .| . .2 . . |
    +-----+-----+--------+----------+
    |LVL2 | 130 | . 2 . .| . .3 . . |
    +-----+-----+--------+----------+
    |LVL3 | 131 | . 3 . .| . .4 . . |
    +-----+-----+--------+----------+
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, i created what table to show witch match must be done to calculate.
    Here is javascript code what matches exp amount for levels:
    Code:
    LVL=new Array();
    LVL[1]=128;
    LVL[0]=128; 
         m=.05;
         for (i=1;i<101;i++) {
          if (i>1) {
           LVL[i]=Math.floor(LVL[i-1]+(LVL[i-1]*m)); 
           m=m+.0015;
          }
         }

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,688
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    F=D-A D-E=128
    E=B+F A-B=128
    D-E=A-B

    You have A and D
    A = 128
    D = 134

    F=D-A = 6
    or, Needed = Exp(n)-Exp(n-1)

    D-E=128 or D=128+E or E=D-128
    In other words, Diff = Exp-128
    E=6 and by the same logic, B=0

    Diff = Exp-128
    Needed = Exp(n)-Exp(n-1)

    +-----+-----+--------+----------+
    |Level| Exp |Exp diff|Exp needed|
    +-----+-----+--------+----------+
    |LVL0 | 128 | . .0. .| . . 0. . |
    +-----+-----+--------+----------+
    |LVL1 | 134 | . .6. .| . . 6. . |
    +-----+-----+--------+----------+
    |LVL2 | 140 | . 12. .| . . 6. . |
    +-----+-----+--------+----------+
    |LVL3 | 147 | . 19. .| . . 7. . |
    +-----+-----+--------+----------+
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know thanks, but i need to create javascript code who will do what match and i stuck on what part, i never created whose matching things in javascript, i only managed to create current exp

  6. #6
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,688
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    Well you now have the formulas that you need.

    Diff = Exp-128
    Needed = Exp(n)-Exp(n-1)
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  7. #7
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes i know them but i don't know how to white them using javascript.

  8. #8
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,688
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    Here is your existing code, rewritten in a slightly better way.

    Code javascript:
    var lvl = [
    	{exp: 128, diff: 0, needed: 0},
    	{exp: 128, diff: 0, needed: 0}
    ],
    	m = 0.05,
    	i,
    	oldLvl;
    for (i = 2; i <= 100; i += 1) {
        oldLvl = lvl[i - 1];
        lvl[i] = {};
        lvl[i].exp = Math.floor(oldLvl.exp + (oldLvl.exp * m));
        m = m + 0.0015;
    }

    Here is that same code with my suggested updates.

    Code javascript:
    var lvl = [
    	{exp: 128, diff: 0, needed: 0},
    	{exp: 128, diff: 0, needed: 0}
    ],
    	m = 0.05,
    	i,
    	oldLvl,
    	exp;
    for (i = 2; i <= 100; i += 1) {
        oldLvl = lvl[i - 1];
        lvl[i] = {};
        exp = Math.floor(oldLvl.exp + (oldLvl.exp * m));
        lvl[i].exp = exp;
        lvl[i].diff = exp - 128;
        lvl[i].needed = exp - oldLvl.exp;
        m = m + 0.0015;
    }
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  9. #9
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow!
    Thank you very much


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
  •