Enjoy an ad free experience by logging in. Not a member yet? Register.

Results 1 to 15 of 25
Thread: Coding a Forum Level Up System

01232013, 12:46 AM #1
 Join Date
 Jan 2013
 Posts
 12
 Thanks
 0
 Thanked 0 Times in 0 Posts
Coding a Forum Level Up System
I'm working on modifying someone else's code for allowing forum posts to register towards a pool of experience towards leveling up. This is the original section which has been edited:
Code:var plevel = Math.floor(EXP/xneeded+parseInt(1)); var xpup = (plevel*xneeded) var showxp= (xpupxneeded) if(sPost.innerHTML.match('<! placeholder >')) { NewCode = sPost.innerHTML.replace("<! placeholder >", ""+name + ": " + sign + EXP + "<br><! placeholder >") } else { NewCode = topR + midR + name + ": " + sign +" "+ Math.floor(EXP/xneeded+parseInt(1)) + "<BR> XP: "+ (EXPshowxp) +"<BR> Experience needed: " + (xpupEXP)+ "<BR>Overall Experience:" + (xneeded * (EXP/xneeded)) +"<br><! placeholder ><br><br>" } sPost.innerHTML = NewCode }} </script>
Code:if (EXP<600) { plevel = 1 } else if (600<EXP<700) { plevel = 2 } else if (650<EXP<750) { plevel = 3 } else if (800<EXP<900) { plevel = 4 } else if (900<EXP<1000) { plevel = 5 } else if (1050<EXP<1200) { plevel = 6 } else if (1200<EXP<1350) { plevel = 7 } else if (1350<EXP<1550) { plevel = 8 } else if (1550<EXP<1800) { plevel = 9 } else if (1800<EXP<2050) { plevel = 10 } else if (2050<EXP<2350) { plevel = 11 } else if (2350<EXP<2700) { plevel = 12 } else if (2700<EXP<3100) { plevel = 13 } else if (3100<EXP<3550) { plevel = 14 } else if (3550<EXP<4100) { plevel = 15 } else if (4100<EXP<4700) { plevel = 16 } else if (4700<EXP<5400) { plevel = 17 } else if (5400<EXP<6200) { plevel = 18 } else if (6200<EXP<7150) { plevel = 19 } else if (7150<EXP<8200) { plevel = 20 } else if (8200<EXP<9450) { plevel = 21 } else if (9450<EXP<10850) { plevel = 22 } else if (10850<EXP<12450) { plevel = 23 } else if (12450<EXP<14350) { plevel = 24 } else if (14350<EXP<16500) { plevel = 25 } else if (16500<EXP<18950) { plevel = 26 } else if (18950<EXP<21800) { plevel = 27 } else if (21800<EXP<25050) { plevel = 28 } else if (25050<EXP<28800) { plevel = 29 } else { plevel = 30 } var xpup = (xneeded * Math.ceiling(Math.pow(1.15, plevel))) var showxp= (xpup  (xneeded * Math.ceiling(Math.pow(1.15, plevel1))) if(sPost.innerHTML.match('<! placeholder >')) { NewCode = sPost.innerHTML.replace("<! placeholder >", ""+name + ": " + sign + EXP + "<br><! placeholder >") } else { NewCode = topR + midR + name + ": " + sign +" "+ if (EXP<600) { plevel = 1 } else if (600<EXP<700) { plevel = 2 } else if (650<EXP<750) { plevel = 3 } else if (800<EXP<900) { plevel = 4 } else if (900<EXP<1000) { plevel = 5 } else if (1050<EXP<1200) { plevel = 6 } else if (1200<EXP<1350) { plevel = 7 } else if (1350<EXP<1550) { plevel = 8 } else if (1550<EXP<1800) { plevel = 9 } else if (1800<EXP<2050) { plevel = 10 } else if (2050<EXP<2350) { plevel = 11 } else (2350<EXP<2700) { plevel = 12 } else if (2700<EXP<3100) { plevel = 13 } else if (3100<EXP<3550) { plevel = 14 } else if (3550<EXP<4100) { plevel = 15 } else if (4100<EXP<4700) { plevel = 16 } else if (4700<EXP<5400) { plevel = 17 } else if (5400<EXP<6200) { plevel = 18 } else if (6200<EXP<7150) { plevel = 19 } else if (7150<EXP<8200) { plevel = 20 } else if (8200<EXP<9450) { plevel = 21 } else if (9450<EXP<10850) { plevel = 22 } else if (10850<EXP<12450) { plevel = 23 } else if (12450<EXP<14350) { plevel = 24 } else if (14350<EXP<16500) { plevel = 25 } else if (16500<EXP<18950) { plevel = 26 } else if (18950<EXP<21800) { plevel = 27 } else if (21800<EXP<25050) { plevel = 28 } else if (25050<EXP<28800) { plevel = 29 } else { plevel = 30 } + "<BR> XP: "+ (EXPshowxp) +"<BR> Experience needed: " + (xpupEXP)+ "<BR>Overall Experience:" + (xneeded * EXP / xneeded) +"<br><! placeholder ><br><br>" } sPost.innerHTML = NewCode }} </script>

01232013, 01:46 AM #2
Totally bogus:
Code:else if (1200<EXP<1350)
Code:else if ( 1200 < EXP && EXP < 1350 )
Code:else if (600 < EXP && EXP < 700 ) // was: (600<EXP<700) { plevel = 2 } else if (650 < EXP && EXP < 750 ) // was: (650<EXP<750) { plevel = 3 } else if ( 800 < EXP && EXP < 900 ) // was: (800<EXP<900) { plevel = 4 }
The 650 in the second IF will be ignored.
OR what if the EXP is 787?
It doesn't match *ANY* of the IF's so plevel will be just blank.
Try it all over again:
Code:if (EXP<600) { plevel = 1; } else if (EXP<700) { plevel = 2; } else if (EXP<750) { plevel = 3; } else if (EXP<900) { plevel = 4; } else if (EXP<1000){plevel = 5; } ... etc. ...
Be yourself. No one else is as qualified.

01232013, 02:11 AM #3
 Join Date
 Jan 2013
 Posts
 12
 Thanks
 0
 Thanked 0 Times in 0 Posts
Yeaaaah those nonsense ones I totally missed. I'm not sure I understand why your version works, but I'm pretty new to Javascript.
At any rate, I rewrote it based on your comments but something is still breaking it.
EDIT: Okay, it's definitely these two equations:
Code:var xpup = (xneeded * Math.ceiling(Math.pow(1.15, plevel))) var showxp= (xpup  (xneeded * Math.ceiling(Math.pow(1.15, plevel1)))
Last edited by FrostWyrmWraith; 01232013 at 02:51 AM. Reason: Avoiding a double post

01232013, 03:06 AM #4
just run that code in any browser and have a look at the error console. Or open it in a decent code editor which show you the matching brackets  you'll see that this line:
Code:var showxp= (xpup  (xneeded * Math.ceiling(Math.pow(1.15, plevel1)))
and the error console will tell you that there is no such thing as Math.ceiling  you're probably looking for Math.ceilLast edited by xelawho; 01232013 at 03:08 AM.

01232013, 03:25 AM #5
 Join Date
 Jan 2013
 Posts
 12
 Thanks
 0
 Thanked 0 Times in 0 Posts
I don't know how to run the code through a browser :/
At any rate, it works now! Thanks for the help!

01232013, 04:10 AM #6
 Join Date
 Jan 2013
 Posts
 12
 Thanks
 0
 Thanked 0 Times in 0 Posts
Okay, I was wrong, something is still messed up. It's accepting the codes now, but the mathematical output is coming like I didn't change the code at all. The result for:
Code:(xneeded * Math.ceil(Math.pow(1.15, plevel))EXP)
Code:((plevel*xneeded)EXP)
Code:(EXP(xpup  (xneeded * Math.ceil(Math.pow(1.15, plevel1)))))
Code:(EXP(xpupxneeded))
Last edited by FrostWyrmWraith; 01232013 at 07:48 PM.

01232013, 12:56 PM #7
 Join Date
 Jan 2013
 Location
 Germany
 Posts
 578
 Thanks
 4
 Thanked 77 Times in 77 Posts
How about you give us some actual input/output values to make sure your math is right?
Also, parseInt(1) made me laugh. Programming paranoia ... is that a thing?

01232013, 07:53 PM #8
 Join Date
 Jan 2013
 Posts
 12
 Thanks
 0
 Thanked 0 Times in 0 Posts
...well at least the parseint thing wasn't me!
Alright, so, Let's say the person has 50 posts. That makes EXP 50 * 50 = 2500. The xneeded value is a fixed 500.
That makes the level 12. The first equation should be outputting 200 according to that. The second should be giving out 2150. Instead what I'm getting is 500 and 2000. It's basically ignoring everything I've changed, including the plevel values, and doing what would have made sense in the original code.

01232013, 08:24 PM #9
I think it is way way past time that you show us your complete code *AS IT IS NOW*.
And I don't understand this part, at all:I don't know how to run the code through a browser
Oh...and finally...
This code:
Code:if (EXP<600) { plevel = 1; } else if (EXP<700) { plevel = 2; } else if (EXP<750) { plevel = 3; } else if (EXP<900) { plevel = 4; } else if (EXP<1000){plevel = 5; } ...
You have to be able to express a problem in logical terms, in English or whatever your native language is, *FIRST*. Only then can you code it in the computer language of your choice.Be yourself. No one else is as qualified.

01232013, 08:30 PM #10
 Join Date
 Jan 2013
 Posts
 12
 Thanks
 0
 Thanked 0 Times in 0 Posts
I'm putting it into the forum. It's not giving me any error codes or anything like that.
As I understood this forum's rules, I was only supposed to post the part in question. The full code:
Code:<script type="text/javascript"> //Based on the famous money code by gornakle //Transformed in a somewhat more automatic xp code //by Duveaux of http://phantomdesigns.net //Do not remove credit note //If you are using a different var for a level, you may add a sign here var sign = ""; //You may change the name displayed here var name = "Level"; //How much experience does a user needs to get per post? var PerPost = 50; //How much experience will a member start with? var default_amount = 0; //how much experience is needed to level up? var xneeded= 500 //The variable UXP[uname] allows you to alter the experience for a player //Make sure you use capitals and spell the name correct var UXP=[]; UXP["Duveaux"]="100" UXP["OpleX"]='0' // No need to edit below this line! td=document.getElementsByTagName("TD") for(i=0;i<td.length;i++) { if((td[i].className=="post1"td[i].className=="post2")&&td[i].innerHTML.match("Posts: ")&&td[i].width!="100%") { sPost=td[i].getElementsByTagName("SPAN")[0] if(sPost.innerHTML.replace(",","").replace('.','').replace(' ','').match(/Posts: (\d+)/)) Posts = parseInt(RegExp.$1) uname = td[i2].innerHTML.replace(/<[^>]+>/g,"").replace(/ /g,"") if(UXP[uname]){ EXP = (parseInt(UXP[uname]) + (Posts * PerPost))+parseInt(default_amount) } else{ EXP = (Posts * PerPost)+parseInt(default_amount) } var midR="Group: " + sPost.innerHTML.split('Group: ')[1] var topR=sPost.innerHTML.split('Group: ')[0] if (EXP<600) { plevel = 1; } else if (EXP<700) { plevel = 2; } else if (EXP<800) { plevel = 3; } else if (EXP<900) { plevel = 4; } else if (EXP<1050) { plevel = 5; } else if (EXP<1200) { plevel = 6; } else if (EXP<1350) { plevel = 7; } else if (EXP<1550) { plevel = 8; } else if (EXP<1800) { plevel = 9; } else if (EXP<2050) { plevel = 10; } else if (EXP<2350) { plevel = 11; } else if (EXP<2700) { plevel = 12; } else if (EXP<3100) { plevel = 13; } else if (EXP<3550) { plevel = 14; } else if (EXP<4100) { plevel = 15; } else if (EXP<4700) { plevel = 16; } else if (EXP<5400) { plevel = 17; } else if (EXP<6200) { plevel = 18; } else if (EXP<7150) { plevel = 19; } else if (EXP<8200) { plevel = 20; } else if (EXP<9450) { plevel = 21; } else if (EXP<10850) { plevel = 22; } else if (EXP<12450) { plevel = 23; } else if (EXP<14350) { plevel = 24; } else if (EXP<16500) { plevel = 25; } else if (EXP<18950) { plevel = 26; } else if (EXP<21800) { plevel = 27; } else if (EXP<25050) { plevel = 28; } else if (EXP<28800) { plevel = 29; } else { plevel = 30 } var xpup = (xneeded * Math.ceil(Math.pow(1.15, plevel))) var showxp= (xpup  (xneeded * Math.ceil(Math.pow(1.15, plevel1)))) NewCode = topR + midR + name + ": " + sign +" "+ plevel + "<BR> XP: "+ (EXPshowxp) +"<BR> Experience needed: " + (xpupEXP)+ "<BR>Overall Experience:" + (xneeded * EXP / xneeded) +"<br><! placeholder ><br><br>" sPost.innerHTML = NewCode }} </script>

01232013, 08:34 PM #11
But let me make a stab at this, anyway. I'll probably mess up, but w.t.h.
Okay, so you say that:
50 posts means that
EXP = 50 * 50
EXP = 2500
and, yes, I see from your (mildly messed up) table that
if ( EXP == 2500 ) { plevel = 12; }
So then let's look at your first post:
Code:var xpup = (plevel*xneeded) var showxp= (xpupxneeded)
xneeded == 500
SO that means:
Code:var xpup = 12 * 500 ==>> xpup should be 6000. var showxp = 6000  500 ==>> showxp should be 5500.
That makes the level 12. [agreed]
The first equation should be outputting 200 according to that. [I get 6000.]
The second should be giving out 2150. [I get 5500]Be yourself. No one else is as qualified.

01232013, 08:44 PM #12
 Join Date
 Jan 2013
 Posts
 12
 Thanks
 0
 Thanked 0 Times in 0 Posts
That probably has something to do with the fact that you plugged it into the original equation, not the new one. Which does result in 200 and 2150. I made a post following your previous one but it apparently needs to wait for mod approval? Anyway I posted the code and explained that it was acting as if it was reading off the original plevel formula as well, so the plevel input on those original equations isn't twelve but six, which gives you 500 and 2000. You've also missed the last half of the equation and only obtained the xpup and showxp values instead of plugging them then into the equations in I already provided, which give you what appears on the player's profile. Those subtract total EXP from xpup and showxp from total EXP.

01232013, 09:01 PM #13
 Join Date
 Jan 2013
 Location
 Germany
 Posts
 578
 Thanks
 4
 Thanked 77 Times in 77 Posts
No, he just didn't see the post, I guess. But your math is still wrong.
which is neither of the values you said.

01232013, 09:06 PM #14
 Join Date
 Jan 2013
 Posts
 12
 Thanks
 0
 Thanked 0 Times in 0 Posts
Because you also did it wrong.
500*1.15^12=2700 when rounded up.
Never did I say anything about a 1.12. And where did you even get 50?
EDIT: For that matter, both values I gave were from the full equation and you just did the xpup equation minus a random 50.Last edited by FrostWyrmWraith; 01232013 at 09:11 PM.

01232013, 09:18 PM #15
 Join Date
 Jan 2013
 Location
 Germany
 Posts
 578
 Thanks
 4
 Thanked 77 Times in 77 Posts
This is the term* I am talking about. And the 1.12 is just a typo, I used 1.15 (meaning that it is in fact 2950). No random anything because your term* clearly says "EXP".
*) As a mathematician I have a problem with calling this an equation. It simply isn't one.