SitePoint Sponsor 

User Tag List
Results 1 to 9 of 9
Thread: Need help wt Javascript

Jun 25, 2008, 15:57 #1
 Join Date
 Jun 2008
 Posts
 6
 Mentioned
 0 Post(s)
 Tagged
 0 Thread(s)
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[i1]+(LVL[i1]*m)); m=m+.0015; } }
Here is formula:
+++++
LevelExp Exp diffExp needed
+++++
LVLXABC
+++++
LVLYDEF
+++++
LVLY exp needed = DA
LVLY exp diff = B+F
F=DA DE=128
E=B+F AB=128
DE=AB
(levels starts from1 and till 99)
Thanks.Last edited by ignas2526; Jun 25, 2008 at 16:51.

Jun 25, 2008, 20:10 #2
 Join Date
 Jan 2007
 Location
 Christchurch, New Zealand
 Posts
 14,729
 Mentioned
 104 Post(s)
 Tagged
 4 Thread(s)
From your calculations, it seems that the following table will match.
+++++
Level Exp Exp diffExp 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

Jun 26, 2008, 11:31 #3
 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[i1]+(LVL[i1]*m)); m=m+.0015; } }

Jun 26, 2008, 14:24 #4
 Join Date
 Jan 2007
 Location
 Christchurch, New Zealand
 Posts
 14,729
 Mentioned
 104 Post(s)
 Tagged
 4 Thread(s)
F=DA DE=128
E=B+F AB=128
DE=AB
You have A and D
A = 128
D = 134
F=DA = 6
or, Needed = Exp(n)Exp(n1)
DE=128 or D=128+E or E=D128
In other words, Diff = Exp128
E=6 and by the same logic, B=0
Diff = Exp128
Needed = Exp(n)Exp(n1)
+++++
Level Exp Exp diffExp 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

Jun 27, 2008, 11:06 #5
 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

Jun 29, 2008, 13:58 #6
 Join Date
 Jan 2007
 Location
 Christchurch, New Zealand
 Posts
 14,729
 Mentioned
 104 Post(s)
 Tagged
 4 Thread(s)
Well you now have the formulas that you need.
Diff = Exp128
Needed = Exp(n)Exp(n1)Programming Group Advisor
Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
Car is to Carpet as Java is to JavaScript

Jun 29, 2008, 16:26 #7
 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.

Jun 29, 2008, 18:11 #8
 Join Date
 Jan 2007
 Location
 Christchurch, New Zealand
 Posts
 14,729
 Mentioned
 104 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

Jul 13, 2008, 10:37 #9
 Join Date
 Jun 2008
 Posts
 6
 Mentioned
 0 Post(s)
 Tagged
 0 Thread(s)
Wow!
Thank you very much
Bookmarks