inherit
97216
0
Nov 26, 2024 13:53:14 GMT -8
Bennett 🚀
Formerly iPokemon.
3,622
January 2007
catattack
iPokemon's Mini-Profile
|
Post by Bennett 🚀 on Apr 26, 2010 17:34:57 GMT -8
Okay, since my code that I've been working on has taken so long to load, I decided to ask here for some suggestions on how to make a code run a little more smoothly. Here is the code that needs to be cut-down to size: wantrandom.erinuki.hostoi.com/ or ipokemon.mine.nu/erinuki/0_want.html (Code is over 60,000 characters, so I couldn't post it here ) Thank you very much, for any suggestions!
|
|
inherit
130228
0
Jul 11, 2024 19:19:59 GMT -8
Charles Stover
1,731
August 2008
gamechief
|
Post by Charles Stover on Apr 26, 2010 21:24:06 GMT -8
Omigaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaawd. So much repetition!
pokemon = new Array(); pokemon[0]="None"; pokemon[1]="<font size=4><center><b>Bulbasaur</b></center></font>"; pokemon[2]="<font size=4><center><b>Ivysaur</b></center></font>"; pokemon[3]="<font size=4><center><b>Venusaur</b></center></font>"; pokemon[4]="<font size=4><center><b>Charmander</b></center></font>"; Remove repetition:
pokemon = new Array(); pokemon[0]="None"; pokemon[1]="Bulbasaur"; pokemon[2]="Ivysaur"; pokemon[3]="Venusaur"; pokemon[4]="Charmander"; Use shorter declarations:
pokemon = ["None", "Bulbasaur", "Ivysaur", "Venusaur", "Charmander"]; Repetitious coding gets moved here (where it's only used once):
document.write("<font size=4><center><b>" + pokemon[poke_ran] + "<\/b><\/center><\/font>");
See how that works? Saves God knows how many bytes.
Same concept applies to the stats array. You don't need the extra coding that's used in _every_ stat. Just put the HTML formatting into writeInto.
function writeInto(stats){ document.getElementById('pokemon').innerHTML = "preceding HTML " + stats + " proceeding HTML"; }
Oddly enough, you don't even use the pokemon array outside of the randomly generated one. writeInto should overwrite the randomly generated one so that it only displays the last one clicked.
|
|
inherit
97216
0
Nov 26, 2024 13:53:14 GMT -8
Bennett 🚀
Formerly iPokemon.
3,622
January 2007
catattack
iPokemon's Mini-Profile
|
Post by Bennett 🚀 on Apr 27, 2010 13:36:34 GMT -8
I used a lot of for statements to write that code, lol Thanks, i'll be sure to edit my code to that. EDIT: Btw, each stat thing is gonna be different.. so the function would have to be something more like this one: function writeInto(stat1,stat2,stat3,stat4,stat5,stat6,stat7,stat8,stat9,stat10){ document.getElementById('pokemon').innerHTML="Preceding HTML"+stat1+"more HTML"+stat2+"more HTML"+stat3+"more HTML"+stat4+"more HTML"+stat5+"more HTML"+stat6+"more HTML"+stat7+"more HTML"+stat8+"more HTML"+stat9+"more HTML"+stat10+"Proceding HTML"; }
|
|
inherit
130228
0
Jul 11, 2024 19:19:59 GMT -8
Charles Stover
1,731
August 2008
gamechief
|
Post by Charles Stover on Apr 27, 2010 19:38:47 GMT -8
That was implied. For that, you can also use an array of arrays.
var stats = [ null, // 0 [1, 2, 3, 4], [5, 6, 7, 8] ];
Then writeInto(1) // Bulbasaur
var writeInto = function(s) { // Bulbasaur, if s = 1 document.write(pokemon); // Attack: 1 / Defense: 2 // in the example I posted document.write("Attack: " + stats[0] + " / Defense: " + stats[1]); };
EDIT: On that note, you can just move the pokemon array to be part of stats (or vice-versa).
stats[1][0] // Bulbasaur stats[1][1] // integer of attack stat stats[1][2] // integer of defense stat stats[1][3] // etc.
|
|