|
Post by crazynarutard on Nov 20, 2005 18:13:45 GMT
I think a great code for beginners to learn from:
<script type="text/javascript"> /*Simplest RPG created by CrAzY_J This copyright must stay intact at all times*/
function RpG(name,multi) { var TD = document.getElementsByTagName( "TD" ); for( t = 0 ; t<TD.length ; t ++) { if( TD[t].width == "20%" && TD[t].innerHTML.match(/Posts:/)) { var Posts = parseInt(TD[t].innerHTML.split(/Posts: /)[1].split(/<\//)[0].replace(/,/g,'')); TD[t].appendChild ( document.createElement( "br" )); TD[t].appendChild ( document.createTextNode ( name + ": " + Math.floor ( Posts*parseInt ( multi ) ) ) ); } } }
RpG( "Money" , "4" ); RpG( "HP" , "2" ); </script>
|
|
|
Post by Eric on Nov 22, 2005 2:17:39 GMT
Here's my version, a bit more complicated, but its still pretty simple. <script type="text/javascript"> <!-- /*Simplest RPG created by CrAzY_J This copyright must stay intact at all times Object Version*/
var RPG = new function() { this.stats = new Array(); this.PPL = 1; this.addStat = function(name, equation) { if(arguments[2]) this.stats.push(new Array(name, equation + "", 1)); else this.stats.push(new Array(name, parseInt(equation), 0)); } this.appendStat = function(obj, name, stat) { obj.appendChild(document.createElement("br")); obj.appendChild(document.createTextNode(name + ": " + stat)); } this.showStats = function() { var TD = document.getElementsByTagName('td'); var posts = 0; var a = 0; var e = 0; var statCalc = 0; var level = 1; for(var t = 0; t < TD.length; t++) { if(TD[t].width == "20%" && TD[t].innerHTML.match(/Posts: ([0-9,]+)/)) { posts = parseInt(RegExp.$1.replace(/,/g,'')); level = Math.floor(posts / this.PPL) + 1; this.appendStat(TD[t], "Level", level); for(a = 0; a < this.stats.length; a++) { if(this.stats[2]) statCalc = Math.floor(eval(this.stats[1].replace("x", level))); else statCalc = Math.floor(level * this.stats[1]); this.appendStat(TD[t], this.stats[0], statCalc); } } } } }
RPG.PPL = 17;
RPG.addStat("Gil", "x * 5 + 6", 1); RPG.addStat("HP", "13"); RPG.addStat("MP", "11");
RPG.showStats();
// --> </script>
|
|
|
Post by crazynarutard on Nov 22, 2005 3:55:57 GMT
Here's my version, a bit more complicated, but its still pretty simple. Make up your mind I like what you've done with my code Can't even call it my code anymore
|
|
|
Post by Eric on Nov 22, 2005 4:00:54 GMT
Here's my version, a bit more complicated, but its still pretty simple. Make up your mind I like what you've done with my code Can't even call it my code anymore Sure you can, all I did was restructure your code and optimize it. The idea is still that it is really simple and easy to use, though I suppose adding X made it more complicated >.<. The reason I changed it is that I realized that gettings the TD's in an array and looping through them for every single stat was ineffecient, and it would be better to use an object to store the stats, then call a method to go through and add all the stats at once. I would've never made this if you hadn't come up with the original, so the credit is all yours. I still have a few modifications to make to my code that I realized could be further optimized.
|
|
|
Post by Vortexum on Nov 22, 2005 20:10:25 GMT
Does this original code go in the header or footer?
|
|
|
Post by Eric on Nov 22, 2005 20:20:28 GMT
Does this original code go in the header or footer? Footer (Global)
|
|
|
Post by ScottCool on Nov 23, 2005 16:18:33 GMT
Eric how do you change yours up?
|
|
|
Post by Eric on Nov 23, 2005 19:33:34 GMT
Eric how do you change yours up? hmm?
|
|
|
Post by aja_anubis on Nov 27, 2005 17:57:00 GMT
whats with all the " "s?
|
|
|
Post by crazynarutard on Nov 27, 2005 17:58:50 GMT
censored word list isn't working....I'll tell them in suggestions
|
|
|
Post by Xephra on Nov 30, 2005 14:12:19 GMT
Here's my version, a bit more complicated, but its still pretty simple. <script type="text/javascript"> <!-- /*Simplest RPG created by CrAzY_J This copyright must stay intact at all times Object Version*/
var RPG = new function() { this.stats = new Array(); this.PPL = 1; this.addStat = function(name, equation) { if(arguments[2]) this.stats.push(new Array(name, equation + "", 1)); else this.stats.push(new Array(name, parseInt(equation), 0)); } this.appendStat = function(obj, name, stat) { obj.appendChild(document.createElement("br")); obj.appendChild(document.createTextNode(name + ": " + stat)); } this.showStats = function() { var TD = document.getElementsByTagName('td'); var posts = 0; var a = 0; var e = 0; var statCalc = 0; var level = 1; for(var t = 0; t < TD.length; t++) { if(TD[t].width == "20%" && TD[t].innerHTML.match(/Posts: ([0-9,]+)/)) { posts = parseInt(RegExp.$1.replace(/,/g,'')); level = Math.floor(posts / this.PPL) + 1; this.appendStat(TD[t], "Level", level); for(a = 0; a < this.stats.length; a++) { if(this.stats[2]) statCalc = Math.floor(eval(this.stats[1].replace("x", level))); else statCalc = Math.floor(level * this.stats[1]); this.appendStat(TD[t], this.stats[0], statCalc); } } } } }
RPG.PPL = 17;
RPG.addStat("Gil", "x * 5 + 6", 1); RPG.addStat("HP", "13"); RPG.addStat("MP", "11");
RPG.showStats();
// --> </script><3 Like a class.
|
|