He means to split the string up into an array. Also known as a multidimensional array. You would access it like this: Code (text): // genesect -- call second field (evolevel/evopoke) pokemonInfo[649][1] Something like this (can be done better; it's mostly just an example): Code (text): serverStartUp : function() { var pokeStats = []; // multidimensional array to hold stats var pokeStatsTempFile = getFileContent("/db/pokes/poke_stats.txt"); var pokeStatsTempArr = pokeStatsFile.split("\n"); var len = pokeStatsTempArr.length; // not required, but storing the length as an variable will make it faster for(var i = 0; i < len; i++) { pokeStats.push(pokeStatsTempArr.split(" ")); } pokeStatsTempFile = null; pokeStatsTempArr = null; } To access array element: Code (text): function findStat(pokeNum, formId, statId) { // returns stat of a pokemon // for statId, 1 = atk, 2 = def, 3 = splatk, 4 = spldef, 5 = spd var len = pokeStats.length; for(var i = 0; i < len; i++) { if(pokeStats[i][0] == pokeNum + ":" + formId) { return pokeStats[i][statId]; } } return 0; } // gets atk stat of arceus var atk = findStat(493, 0, 1); // gets splatk stat of sky shaymin atk = findStat(492, 1, 3);
They're not hard at all. All you need to know is that a multidimensional array in an element within an array. Kinda gets complicated with 3+ elements though. You can make some global constants to make it easier, though... (well, other than the fact that js doesn't have constants, but that's trivial and won't matter) Code (text): var STAT_ID_ATK = 1; var STAT_ID_DEF = 2; var STAT_ID_SPLATK = 3; var STAT_ID_SPLDEF = 4; var STAT_ID_SPD = 5; // arceus - atk stat sys.sendAll(findStat(493, 0, STAT_ID_ATK));
In my case, would be hard since i do it in this way. Lol: PokeNum|EvoNum/EvoLevel|Ability1/2/3|DWAbility1/2?|Other usefull data here... So that code what exactly does is split all the file (newline) and sets everything in a multidimensional array. Then It splits everything that's spaced and put them somewhere that i'm confused and if i talk more i suicide of confusion, right?
Okay, got stuck. Or that seems. PHP: loadPokemons : function() { var temporaryFile = sys.getFileContent("RPGData/Pokemons.txt"); var temporaryArray = temporaryFile.split("\n"); var length = temporaryArray.length; for(var A = 0; A < length; A++) { PokemonData.push( } temporaryFile = null; temporaryArray = null; } I've always had problem with multidimensional arrays, haha. Whatever, i got stuck on the push part. Okay in tmporaryFile we LIKE "copy" until a \n (Newline) then we're supposed to push everything thats splitted with "|" but wouldn't that make this: 1st element: 001 2nd element: 002/16 3rd element: blablabla Element of array. o.O This is what i exactly have: Code (text): 494|---/--|lot of stuff with | and / missing here! 495|496/17|lot of stuff with | and / missing here! 496|497/36|lot of stuff with | and / missing here! 497|---/--|lot of stuff with | and / missing here! 498|499/17|lot of stuff with | and / missing here! 499|500/36|lot of stuff with | and / missing here! 500|---/--|lot of stuff with | and / missing here! 501|502/17|lot of stuff with | and / missing here! 502|503/36|lot of stuff with | and / missing here! 503|---/--|lot of stuff with | and / missing here! Told you, multidimensional arrays are my enemies ;_; PS: new avatar <3
Code (text): loadPokemons : function() { var temporaryFile = sys.getFileContent("RPGData/Pokemons.txt"); var temporaryArray = temporaryFile.split("\n"); var length = temporaryArray.length; for(var A = 0; A < length; A++) { PokemonData.push("|"); } temporaryFile = null; temporaryArray = null; } Splitting it with "|" will make a new element. This new element will hold another array, which will look like this: PokemonData[][]
Then i'll do: PokemonData[][][][][][][][][] or what? I meant, for every element. PokemonData[495][496/17][blablabla][blablabla]? EDIT: Gah, i got confused again. :confused: Well, how i said i have this: Code (text): 494|---/--| 495|496/17| 496|497/36| 497|---/--| 498|499/17| 499|500/36| 500|---/--| 501|502/17| 502|503/36| 503|---/--| Well, then the following code: PHP: loadPokemons : function() { var temporaryFile = sys.getFileContent("RPGData/Pokemons.txt"); var temporaryArray = temporaryFile.split("\n"); var length = temporaryArray.length; for(var A = 0; A < length; A++) { PokemonData.push( } temporaryFile = null; temporaryArray = null; } Yes, stuck on the push due to splitting issues. Okay, we know that temporaryArray splits all the data. I meant, when it finds a new line, it splits. Leaving it like this: Code (text): 494|---/--| > Split 1 495|496/17| > Split 2 496|497/36| > Split 3 497|---/--| > Split 4 498|499/17| > Split 5 499|500/36| > Split 6 500|---/--| > Split 7 501|502/17| > Split 8 502|503/36| > Split 9 503|---/--| > Split 10 There all goes fine. But then, we have to split every | to leave it like this. Code (text): 494 < Array Element 1 ---/-- < 494 Element 1 --/--/-- < Element 2 Something like that should be done like: PokemonData[494][---/--][--/--/--][--/--][][][] (For other data...) So basically setting data for every dimension. Like this: PokemonData[PokeNum][EvoPoke/EvoLevel][Ability1/2/3][DWAbility1/DWAbility2][][][] Isn't like that? Then to call it, how? How do i get the Pokemon Ability/1/2/3 or DWAbility?
Huh, i've been playing a little with multidimensional arrays. They're basically array of arrays. In my case, they will be array of array of array of array... blabla. I've figured out that first i need an array, i've done this: PHP: ({ afterNewMessage : function(msg) { if(msg == "Script Check: OK") { PokemonData = new Array(1); // Creating an Array with 649 elements. Each element, is one Pokemon. this.loadPokemons(); } } , loadPokemons : function() { var temporaryFile = sys.getFileContent("RPGData/Pokemons.txt"); var temporaryArray = temporaryFile.split("\n"); var temporarySplit = temporaryArray[0].split("|"); for(var i = 0; i < PokemonData.length; ++i) { PokemonData[i] = new Array(3); /* sys.sendAll(temporarySplit[0]); // Debuging purposes, if fine should return the pokenum data. sys.sendAll(temporarySplit[1]); // Debuging purposes, if fine should return the evolution data. */ PokemonData[i][0] = temporarySplit[0]; // Pokenum PokemonData[i][1] = temporarySplit[1]; // PokeEvo/EvoLevel sys.sendAll(PokemonData[i][0]); sys.sendAll(PokemonData[i][1]); } temporaryFile = null; temporaryArray = null; } That code works, PERFECTLY. Basically, i first need to split every | that is find in the first line. Then create another dimension, which is done by doing PokemonData = new Array(1) (In this case 1 just i'm storing PokeNum and PokeEvo/EvoLevel), then just setting the data for each dimension. With that i'm done, it sets all the data for every Pokemon in the Array. (Will it load fast... I meant, 649 elements :/) If there's any way to optimize the code, would be cool if someone helps me with that. Hehe.
Heh, also what about RPG Locations (I meant, cities, routes, caves, etc) Which are the double, triple or even cuadruple than Pokemon Data. And Walks? Maybe x5 bigger than Pokemon Data. :/
Fast processors work. Try removing some of the tiers(I hope your not making a battle+rpg server), it makes loading faster.