Well, since i'm doing an RPG (Said this... 500 times lol) we know that i'm storing around 1.000 - 1.500 Values (Pokémons, Areas, Walks, Player Data, etc) I heard that Registry Values are slow, either reading from files and MySQL is not done but i don't think it's a good way either... So, what's the best way to store all that data outside from scripts? Fast read / fast write and if it's possible an example. Thanks ^^
You can only use files and registry unless you plan on using poorly supported sys.system-function (= you can't get output of commands unless you write it into a file and then read it. really ugly, stay away). For reading, try to cache values in memory. For writing, either write stuff periodically in bunches after caching, or use sys.appendToFile instead of sys.writeToFile. Po scripts have MemoryHash for some implementation of a file saved to disk. Honestly I haven't benchmarked if it's faster with MemoryHash's custom format or by using JSON.parse and JSON.stringify to parse and serialize. The main thing is, cache data instead of opening a file every time out want to read values (sys.getVal...)
Something like this? And.. i never used JSON before :/ Code (javascript): var writeFile = "GameStats.json"; // Example cache = new function() { this.write = function(keyname,data) { hash[keyname] = data; // Incase you want instand storage // this.savecache(); }; this.remove = function(keyname) { delete hash[keyname]; // Instand storage // this.savecache(); }; this.get = function(keyname) { if(typeof(hash[keyname]) == "undefined") return undefined; // Or any other boolean. return hash[keyname]; }; this.clearcache = function() { hash = {} sys.writeToFile(writeFile,""); }; this.init = function() { if(typeof(hash) == "undefined") { hash = {}; } sys.appendToFile(writeFile,""); if(sys.getFileContent(writeFile) != "") { hash = JSON.parse(writeFile); // Not sure... i never used json :/ } }; this.savecache=function () { sys.writeToFile(writeFile,JSON.stringify(hash)); }; this.startAutoSave = function() { // Auto saves every hour // sys.callLater("cache.savecashe()",60*60); // Or is it this. ? ._. }; } Ex for script: Code (javascript): ({ serverStartUp : function() { cache.init(); cache.startAutoSave(); } , afterLogIn : function(src) { if(cache.get("muted*"+sys.ip(src)) == true) SESSION.users(src).muted = true; // Small session part } , beforeChatMessage(src,msg,cid) { if(command == "mute") { // Too lazy to add command structure. This is an example anyway cache.write("muted*"+sys.dbIp(commandData),true); } if(command == "unmute") { cache.remove("muted*"+sys.dbIp(commandData)); } }, }) Tell me if theres something wrong with it. Im not really good with using JSON in scripts :/
Just read using files. There's nothing wrong with it, provided of course that you do it properly. (Don't have database files with like 10000 lines.) I've done an RPG system with PO awhile back, and had no problems with that even with many users on. JSon is a bit slower. Just split the data into an array from the files. JSon uses serialization techniques among others that (in my benchmarks, many JavaScript books, and basically according to logic considering how they are implemented into JavaScript) slow down the script (very minimally, so it depends on how much of a performance boost you want). JSon is good in this case for making things a bit easier (hashes), however. I hope the idea here isn't to store persistent data in cache. Obviously, that won't work. But, what you should do is call the files in the init and cut them up into arrays (cut them up in the init, not when you need them). Create some functions to modify, delete, access, and save the data. You certainly won't want to use MySQL for fast storage because there is no way to directly access an MySQL database. Now, if you're hoping to have a lot of users on your RPG, keep in mind that your PC, no matter which native method you use, may not be able to handle all of it. And now I get banned. :)
The fastest way to store data is to make a proxy that will translate post requests into database calls to something like mongodb or redis.
There could be one, but since no developer other than me bothered do a thing about it… I doubt it is going to happen any time soon. Also, if you read on load, save on exit, be sure to save sometimes while running too, in case of server crashhhhhhhhhhhhhhh
With the function to call a website and get a response. I call mywebsite link (for example: trololol.com/Banning.php?action="Ban"&ip=127.0.0.1) Still not done the system, either if it'll work.
You can do that, sure. But that's going to be very slow. Doing that means, in simplistic terms: http request sent to server -> server-side language processes page -> mysql/database/filesystem is opened -> data read/written among other things -> client side response Simply using append file only means opening the filesystem and reading/writing a file. Which is much faster. Only thing that would be a problem, it seems, is that you apparently intend to have an 'RPG site', which, unless hosted on your PC, probably couldn't easily connect to your filesystem.
Seems you don't understand databases. Nor the limits of JavaScriptCore. Text files and JavaScript object work properly IF and ONLY IF the dataset is small. You can get by with a bit more if you use V8 for your server, but hardly anyone does. At a certain point your JavaScript engine will explode. MySQL can handle very very large data sets. Redis, CouchDB and MongoDB are also VERY fast. When you use them async, it runs very smoothly. Second, JSON is a native JavaScript object. It isn't "implemented", neither in V8 or JavaScriptCore (the default). Any "implemented" JSON object is going to be several times slower than the native one, and the native one is glitch-less, any problems you have with it is simply you not understanding how it works.
sys.system is the best of all, but, you need to know all commands, and know how/why to use them(You can install MySQL, and then run it using sys.system) ;~;
sys.system isn't great. Your relying on another process you just started. A good example of why web call is the best way to work with dataBases: http://pastebin.com/SfyeEEAd 9000 md5 hashes, it cut off though, calculated in about 10-30 seconds or so, though I think that was the printing code. During the mean time, I was still able to type into the server while it was hashing. Code (text): (function() { var args, counter, web, x; web = this.sys.webCall; counter = 0; x = 9000; while (x--) { args = { hash: x }; (function(x) { return web('http://localhost:5083/', function(resp) { return print("MD5 hash when x is " + x + ": " + resp); }, args); })(x); } new Object; }).call(this); Coffee code: Code (text): http = require 'http' crypto = require 'crypto' query = require 'querystring' myServer = http.createServer (req, resp) -> content = '' req.on 'data', (data) -> content += data.toString() req.on 'end', -> obj = query.parse(content) myhash = crypto.createHash('MD5') myhash.update obj.hash resp.end(myhash.digest('hex')) myServer.listen 5083 This isn't a database, but it shows the concept.
phuck yeah 9000 web calls. Anyway, it you are doing heavy calculatations, web calls are probably the best way since it allows script thread to work while web call is being processsed by the server. However, for reading simple things, reading objects should be a lot faster ...
I didn't understand anything of those snippets lol. Explain them in nub mode =( By the way, Webcall is a very insecure method. (Mean, if someone get's the link to all the files in your Site... for example LoadPlayer.php SavePlayer.php) and they get the action, and all data that's managed (I don't know how to explain it very well) would be a way to "hack" my Savefile.
RPGs are rarely simple. Of course, if it is simple enough, you don't need anything, and it'll fit into javascript memory. This is a way to expand past that. But seriously, only use either A: JSON Objects, or B: a local server DB. don't try using files with arrays, it doesn't work well if you want anything complicated. Better yet, have a second server work with the javascript objects, then you don't wast PO server time looping in for loops. Code (text): web('http://localhost:5083/', function(resp) { return print("MD5 hash when x is " + x + ": " + resp); }, args); Connects to localhost, on port 5083, and sends an object "{ hash: <value of x> }", then the server responds with the hash of x, and it's sent to function (resp) { ... }
Since i don't know how to use JSON. I think i'll use local server DB... But. How do i exactly create one? Also, how to access to it though the scripts? Seems complicated lol
JSON is easy. Code (text): jbug = function() { var a, _results; a = 1 <= arguments.length ? Array.prototype.slice.call(arguments, 0) : []; _results = []; while (a.length) { _results.push(print("> " + JSON.stringify(a.shift()))); } return _results; }; myObject = { people: ['you', 'me'], admins: ['localhost'], ranks: {bob:'noob','fish':'noob23'} } JSONstuff = JSON.stringify(myObject); sys.writeToFile('jsonobj.json',JSONstuff) otherObject = JSON.parse (sys.getFileContent('jsonobj.json')) jbug(otherObject) But if you want a local db there are lots of ways to do it. The way I'd go about it is to make a coffeescript server like the one above, only instead of using MD5 hashes, add in Redis. That would take a bit of time though, but it'd be worth it if you wanted a large database.
I'm quite aware JSON is native. The point is that it has to manipulate data in ways that goes beyond the basic binary manipulation of JavaScript. If you handle arrays CORRECTLY (rather than relying on huge, unorganized arrays) there will be absolutely no problem and performance will be much greater than calling from a web site. But I think I misunderstood something: I thought you were trying to connect to a web site, rather than the server itself. In that case, using MongoDB will probably be faster. (You could use MySQL too, but MongoDB tends to be much faster and simpler, again depending on if you properly structure it.) You should probably include some comments in your code. This guy is obviously new to these sorts of things. Looking at that kind of stuff as a newbie is probably fairly cryptic.
Well now i think i'll use files or values. Let's take out MySQL since it's slow and there's no way (Of what i understood) to connect to a local database... Caching or JSON, i don't finish to understand them (I'm very nooby...) So it seems that i'll use files or RegValues. :/
Don't use reg values. You're asking for extreme slowness there (correct me if I'm wrong). Files and arrays are a good choice if you handle them correctly - don't get overzealous with them. Make sure you only keep things that you need. Store user information in separate files. Despite what Insect will probably tell you, it is highly viable to use files and arrays if you use them correctly. I've done so with over 220 users on without any hitches, because it was coded correctly. MySQL is lightning fast if you use it correctly (indexing, optimization, etc.) However, for a newbie, I'm not so sure I would recommend it. Most of the time, newbies have very poor optimization skills. Caching in the way you want to do it should basically just involve calling the necessary data in the init prototype. Only call user information when the user logs in, and dispose of it when they log out.
Well, it's a web server either way. But json only has to manipulate data on JSON.parse and JSON.stringify, JSON.parse produces a normal javaScript object, and JSON.stringify creates a normal javascript string. It's no slower as long as you don't save it every second or something.
JSON is slower, but only by milliseconds. It really won't matter in this case, I'm guessing, provided you handle it correctly. As I've been saying, handling things with the best practices will be by far the best outcome (that means putting performance over simplicity of code in many cases). It would be a good idea to look on Google for JavaScript performance tips (more than just one website) if you're really serious about improving performance.
JSON only runs when you load and save it. Otherwise it's just javascript objects. a = { n: 4 } b = JSON.parse('{"n":4}') a and b are both the same, except that they are different objects. Neither a nor b is faster. Though it will take a bit longer to create b than a. It should be noted however, that the overhead of string.split is about the same as JSON.parse, so there isn't any reason not to use it.
Just nerd speak. I've done numerous RPGs for companies (not for PO; I've done one for PO on my spare time but I stopped it). When I do RPGs, I usually use MySQL. However, I wouldn't recommend it for this simply because you have better options and because an RDBMS will probably be hard to handle for a newbie. For what you're doing, I will recommend the following: - call the necessary data from the filesystem in the init prototype (so that it is global and not calling it everytime a user logs in). You could just use PO's built in data scripts, the ones it uses for pokemon moves, etc. If you do, I recommend copying the folder with a different name so that you can modify files as you wish. - do not call user information in init, call it when that user logs in. use init for information that will be used widely over the server. - for user information, store it in separate files. you don't want files with 10000 lines. - don't be overzealous. when a user logs out, delete all info that they were using. ikr ._.
Wait... Astruvis here?! =O?!?!!??! (? Skarm, i understand some of those ways. Except one, prototype. Hehe. Also, when i load the player data from a file, i basically store that data in variables so when user logouts, the data is saved to the files to avoid loading/saving every time a change is done, right?
Your code should have something that looks like: Code (text): serverStartUp : function() { // stuff } That's the init function. Yes, that is one way to do it. In order to have some protection against crashes, you should save all data at certain intervals.
Yeah, but wait. I should make an array with over (How many pokemons exist lol?) and store their data on that array? o.O Okay, so seems that i'll use files! =)
There is a /db/ folder in the pokeymon server folder. If you plan to use that folder in the RPG, you should call the files you need from it in the init function. Then, use the split() javascript function to store the data in an array so you aren't splitting the data every time you want to use it.
Yes, i get that. But i meant, if i store all the Pokemon Values (PokeNum, between other type of data...) isn't bad to have an Array with over 600 elements? Since the data in the array will be something like this every element: PokeNum|EvoLevel/EvoPoke|Ability1/Ability2/Ability3|DWAbility/DWAbility1(Does a pokemon haves 2 or more DW Abilities? Lol)| blablabla
Store array of arrays... don't put strings there plz plox. Array with 600 elements is nothing... You need a lot more data than that to be in trouble.
Wait, explain the first thing... Store array of arrays... Think you've said that before, don't record. Just for sure, explain ahahaha.(5:30 am, i'm sleepy. -._.-)