File object help [More Questions]

Author Topic: File object help [More Questions]  (Read 2761 times)

You'd still want to break it down into parts at some point for storage. Keeping it all in one file means longer and longer loading times with each new person added. If the server is popular enough, it could get to there point where there's a significant lag spike with each load. Pecon's server stalls for like fifteen seconds during the startup because of a really simple IP logger script that saves them all to a single file.
It loads via the exec() command, so it really wont be an issue. You can execute scripts with thousands of lines with 0 lag, so that wouldn't change here. Pecon's server doesn't use scriptobjects.

Don't place your config files in config/yourAddOn, place them in config/server/yourAddOn or config/client/yourAddOn.

It loads via the exec() command, so it really wont be an issue. You can execute scripts with thousands of lines with 0 lag, so that wouldn't change here. Pecon's server doesn't use scriptobjects.
Don't really see how what's in the file affects load time compared to how much is in it. Saving 10 stats per person with a popular server can, over time, turn into a ten thousand line script. If it ever gets to that point you'll have to deal with it anyway. Better to do it right from the start.

Don't place your config files in config/yourAddOn, place them in config/server/yourAddOn or config/client/yourAddOn.
Already did this.

And on the topic of creating a different file for each person, I've already thought this through but my question is

If I create a new file for every player, so that executing it won't cause lag, say I have 30 players online, wouldn't it lag having 30 different scriptobjects at once constantly doing things on their own?

EDIT;
Also, currently the .txt file that holds the scriptobject looks as so:
Code: [Select]
//--- OBJECT WRITE BEGIN ---
new ScriptObject(Data) {
      data999999_name = "JazZ";
      data999999_level = "10";
};
//--- OBJECT WRITE END ---
Truthfully this is extremely ugly, not that it absolutely matters, but can I remove the comments via script, not asking how, but will it mess up executing it?
« Last Edit: November 01, 2012, 02:03:01 PM by ¥ola »

those comment lines tell the save function where to save it to. Anything inbetween those lines will be overwritten by an object saved to that file.

those comment lines tell the save function where to save it to. Anything inbetween those lines will be overwritten by an object saved to that file.
Well that's a shame

If you do a script object for every client then you'll have to write your own loading system. Ask yourself this, how am i going to tag a script object to the right client (or any for that matter) when they first connect to the server when simply using exec. You can't.

If you haven't figured anything out by the time i get off work, i'll show you how to do this.
« Last Edit: November 01, 2012, 02:42:38 PM by elm »

If I create a new file for every player, so that executing it won't cause lag, say I have 30 players online, wouldn't it lag having 30 different scriptobjects at once constantly doing things on their own?
Not at all. 30 objects is a minuscule amount, especially for something so simple. Shooting someone with the default gun in a DM would take more processing power than maintaining them.

Don't really see how what's in the file affects load time compared to how much is in it. Saving 10 stats per person with a popular server can, over time, turn into a ten thousand line script. If it ever gets to that point you'll have to deal with it anyway. Better to do it right from the start.
I'm pretty sure you can execute massive script files with no lag. I think the execution system torque has staggers the execution so that other logic gets processed while it's executing, otherwise mods like RTB would lag your blockland while they executed.

I'm pretty sure you can execute massive script files with no lag. I think the execution system torque has staggers the execution so that other logic gets processed while it's executing, otherwise mods like RTB would lag your blockland while they executed.
If that's the case, you'll still have some delay for each client, maybe not lag, but either way, it's not loading thousands of lines instantly. Putting each in their own file ensures you only load what you need for each person, and takes the same amount of space to store. Possibly less, even, because the variable names in the file don't have to be marked with the ID, because they can be assumed to match the file name.

script execution is run in real time, it will lag your blockland.

Just try to exec any file in your add-ons folder and you will find that your blockland will probably freeze for several seconds while it compiles and loads the scripts needed.

That is why script execution is handled while blockland itself or a server is loading.  That way you don't notice the game stopping while everything loads, because loading is what it is supposed to be doing.


Also to answer the question on how to overwrite specific lines, the answer is you can't.  You need to read the whole file, save it to an array or something, change the value of the specific index in the array, then write it all back.  File I/O in torque isn't very efficient.

Loading system for SO save files:

function gameConnection::loadData(%this)
{
   //set the path
   %path = "..path..";
   %f = new fileObject();
   %f.openForRead(%path);
   
   while(!%f.isEof())
   {
      %l = %f.readLine();
      
      //Could use a better check method but this is fine for me
      if(strStr(%l,"BEGIN") >= 0 || strStr(%l,"END") >= 0)
         continue;
      
      //append to var
      //method could cause problems with lots of data
      %so = %so @ %l;
   }
   
   eval("%nso = " @ %so);
   
   if(isObject(%nso))
   {
      echo("Script object from file ==> " @ %nso @ ".");
      
      //tag the client
      %this.dataObject = %nso;
      
      return %nso;
   }
   else
      echo("Script object from file ==> failed to load.");
   
   return -1;
}

Loading system for SO save files:

function gameConnection::loadData(%this)
{
   //set the path
   %path = "..path..";
   %f = new fileObject();
   %f.openForRead(%path);
   
   while(!%f.isEof())
   {
      %l = %f.readLine();
      
      //Could use a better check method but this is fine for me
      if(strStr(%l,"BEGIN") >= 0 || strStr(%l,"END") >= 0)
         continue;
      
      //append to var
      //method could cause problems with lots of data
      %so = %so @ %l;
   }
   
   eval("%nso = " @ %so);
   
   if(isObject(%nso))
   {
      echo("Script object from file ==> " @ %nso @ ".");
      
      //tag the client
      %this.dataObject = %nso;
      
      return %nso;
   }
   else
      echo("Script object from file ==> failed to load.");
   
   return -1;
}

i might be missing something...
but whats the difference between that
and just doing

function gameConnection::saveData(%this)
{
%this.dataObject.setName("SAVE_" @ %this.bl_id);
%this.dataObject.save("config/server/bigstuff" @ %this.bl_id @ ".cs");
}
function gameConnection::loadData(%this)
{
exec("config/server/bigstuff"@ %this.bl_id @ ".cs");
%this.dataObj = "SAVE_" @ %this.bl_id;
%this.dataObj.setName("");
}


??

Fixed
« Last Edit: November 02, 2012, 09:19:43 AM by Brian Smithers »

i might be missing something...
but whats the difference between that
and just doing

function gameConnection::saveData(%this)
{
%this.dataObject.setName("SAVE_" @ %this.bl_id);
%this.dataObject.save("config/server/bigstuff" @ %this.bl_id @ ".cs");
}
function gameConnection::loadData(%this)
{
exec("config/server/bigstuff.cs");
%this.dataObj = "SAVE_" @ %this.bl_id;
%this.dataObj.setName("");
}


??

Slow down young jedi, and re-read your code.

otherwise mods like RTB would lag your blockland while they executed.

They do. Heavily, at that. Time how long it takes to start the Blockland client/server with/without RTB.