Author Topic: saving a word for a player  (Read 1085 times)

how could i export a player's bl_id and a name (e.g. name of planet, spaceship, city) when a player does a command (e.g. /setname [targeted player's namehere] [newnamehere])

to a file or as a variable?
what do you mean by export?

to a file or as a variable?
what do you mean by export?
to a file

Code: [Select]
%fileObject = new fileObject();
%fileObject.openForWrite("config/names/" @ %client.BL_ID @ ".txt");
%fileObject.writeLine(%client.BL_ID TAB %client.getPlayerName() TAB %whateverElse);
%fileObject.close();
%fileObject.delete();

I think the easiest way to do what you want to do is to save all your information to some kind of global array like this:

$mydata[%bl_id1] = "thingy";
$mydata[%bl_id2] = "im fat";
$mydata[%bl_id3] = "cake";

then you can do this to save the entire array:

export("$mydata*", "config/server/mydata.cs");

then when you want to reload it, you just run

exec("config/server/mydata.cs");

I think the easiest way to do what you want to do is to save all your information to some kind of global array like this:

$mydata[%bl_id1] = "thingy";
$mydata[%bl_id2] = "im fat";
$mydata[%bl_id3] = "cake";

then you can do this to save the entire array:

export("$mydata*", "config/server/mydata.cs");

then when you want to reload it, you just run

exec("config/server/mydata.cs");
Wouldn't that be inefficient if thousands of people end up joining throughout the servers lifetime? Tons of words saved onto arrays, loaded each time the servers up..?

Wouldn't that be inefficient if thousands of people end up joining throughout the servers lifetime? Tons of words saved onto arrays, loaded each time the servers up..?

Well frankly with torquescript loading one file with one variable in it is not much faster than loading one file with a thousand, and I would rather have one file with thousands of lines in it that 1000 files each with one line.  Sure from a massive scale/big data server perspective you want to be able to move old information off of RAM and only load it when you need it, but this is blockland we are talking about.

To put this into perspective, I hosted a CRPG for not that long and my user data folder has 430 individual entries, one for each person. On a smaller project, being generous, let's say that for each player there is the need to store 6 entries about them, that is 2580. As this project sounds, there needs to be a lot of data stored. Just brainstorming and guessing I would assume that there is need to save the player's financial data, spaceship name, city name, city progress, level, fund income, if one would be making something like a strategy game with separate buildings to manage, you'd also have to keep track of those, if all that would be true then one can safely assume each player needs at least 15 entries if the game goes in-depth enough, that's if there would be no individual skill progression. So 15 entries for each player, for 430 players would take 6450 variables to load at startup.
Keep in mind, 430 players is a low number, my server didn't run for very long and CRPG-s are not appealing to many people while an original concept like this certainly would be.

Now as to actually help the OP, here is how I am handling loading and saving data. Do NOT use this, it is a WIP, I just copied it straight from my very WIP mod, that and this is custom-made to fit the mod I am making and would do well only in a few scenarios I can think off from the top of my head.

Pastebin

Unrelated side-note, if someone can advise me how to remake the item saving-loading, let me know via steam.
« Last Edit: July 21, 2015, 03:46:47 AM by Dannu »

Wouldn't that be inefficient if thousands of people end up joining throughout the servers lifetime? Tons of words saved onto arrays, loaded each time the servers up..?
I believe it's a tradeoff between that and the clutteriness of thousands of one line files

I had a chatbot that learned from the chat. It stored it's data in the form of gigantic two-dimensional arrays, which was saved with export and loaded with exec. export yielded a couple megabyte file; a believe a few hundred thousand lines, yet the export had no noticeable effect on speed. Loading that many lines with exec was slow, a few minutes to load, but it only needed to do it once on server load. And that's with a large file, a few thousand lines shouldn't be noticeable

If you have several values per ID, I'd split it for organization purposes. But for just one, a single file is fine
« Last Edit: July 21, 2015, 11:31:33 AM by Headcrab Zombie »