File object help [More Questions]

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

On an 3rd generation Intel i7, it freezes Blockland for about 3 seconds to execute it for the first time.
On a 6 core i7 980 extreme edition clocked at 4.5ghz, Blockland freezes for about 0 seconds to execute it for the first time.

Just asking, at what filesize would executing a script every so often (4 - 5 minutes maybe) cause an indecent amount of lag?
You only need to execute it on server startup, the variables won't go away randomly.
« Last Edit: November 02, 2012, 06:47:33 PM by Trinick »

You only need to execute it on server startup, the variables won't go away randomly.

Untrue.
The variables need to be reloaded every time the player reconnects.

Untrue.
The variables need to be reloaded every time the player reconnects.
This isn't true at all. They'll persist.

This isn't true at all. They'll persist.

So you're telling me if I do findclientbyname(Bla).testvar = "Gram";

When "Bla" leaves and rejoins his testvar variable will still be Gram?

I find that extremely hard to believe

So you're telling me if I do findclientbyname(Bla).testvar = "Gram";

When "Bla" leaves and rejoins his testvar variable will still be Gram?

I find that extremely hard to believe
No, I'm saying that if you do MyDataObject.data[findClientByName(bla).BL_ID, "testvar"] = "Gram";

When "Bla" leaves the game and rejoins, MyDataObject.data[findClientByName(bla).BL_ID, "testvar"] will still be "Gram". Then you only need to push the variable from MyDataObject onto his client, not re-execute the entire data holder.

No, I'm saying that if you do MyDataObject.data[findClientByName(bla).BL_ID, "testvar"] = "Gram";

When "Bla" leaves the game and rejoins, MyDataObject.data[findClientByName(bla).BL_ID, "testvar"] will still be "Gram". Then you only need to push the variable from MyDataObject onto his client, not re-execute the entire data holder.

How would I go about "pushing" it to the client upon entering then?

How would I go about "pushing" it to the client upon entering then?
findClientByName(bla).testvar = MyDataObject.data[findClientByName(bla), "testvar"];

Or, with the function I supplied you,

MyDataHolder.loadPlayerData(findClientByName(bla));

findClientByName(bla).testvar = MyDataObject.data[findClientByName(bla), "testvar"];

Or, with the function I supplied you,

MyDataHolder.loadPlayerData(findClientByName(bla));

Code: [Select]
function loadPlayerData()
{
while(isObject(MyDataHolder))
MyDataHolder.delete();
exec("config/My_Addon/PlayerData.cs");
}

That's executing the script all over again...

Code: [Select]
function loadPlayerData()
{
while(isObject(MyDataHolder))
MyDataHolder.delete();
exec("config/My_Addon/PlayerData.cs");
}

That's executing the script all over again...
I didn't say "loadPlayerData(findClientByName(bla));"

I said "myDataHolder.loadPlayerData(findClientByName(bla));" which would call
Code: [Select]
function MyDataHolder::loadPlayerData(%this, %client)
{
%client.playerLevel = %this.data[%client.BL_ID, "level"];
%client.money = %this.data[%client.BL_ID, "currency"];
%client.otherVariable = %this.data[%client.BL_ID, "otherVariable"];
}

I didn't say "loadPlayerData(findClientByName(bla));"

I said "myDataHolder.loadPlayerData(findClientByName(bla));" which would call
Code: [Select]
function MyDataHolder::loadPlayerData(%this, %client)
{
%client.playerLevel = %this.data[%client.BL_ID, "level"];
%client.money = %this.data[%client.BL_ID, "currency"];
%client.otherVariable = %this.data[%client.BL_ID, "otherVariable"];
}

Then what is the purpose of
loadPlayerData()
?

Then what is the purpose of
loadPlayerData()
?
For when the server first starts to load the MyDataHolder object with all it's variables.

For when the server first starts to load the MyDataHolder object with all it's variables.

Wow, alright, sounds good to me.

Thanks mate

What are you talking about?

aids research on live primates in cambodia

function gameConnection::loadData(%this)
{
   //set the path, we'll use an example for now
   %path = "config/server/yourmodname/clientdata/" @ %this.bl_id @ ".txt";
   
   //open a new file object for reading purposes
   %f = new fileObject();
   %f.openForRead(%path);
   
   //while the file we have open is not at the end (eof = end of file), loop and run code
   while(!%f.isEof())
   {
      %l = %f.readLine();
      
      //Could use a better check method but this is fine for me
      //This is to ignore the annotations the script object automatically throws into the file

      if(strStr(%l,"BEGIN") >= 0 || strStr(%l,"END") >= 0)
         //continue basically means, go back to the top and ignore everything below
         continue;
      
      //append to var
      //method could cause problems with lots of data

      %so = %so @ %l;
   }
   
   //so basically, we put every line into one variable
   //but now we need to actually create the script object
   //so we will use eval to do so
   //pretty much saying, %nso = new scriptObject(){vars,etc};

   eval("%nso = " @ %so);
   
   //did the code we tried to eval actually create a script object?
   if(isObject(%nso))
   {
      echo("Script object from file ==> " @ %nso @ ".");
      
      //tag the client
      //so now, %this.dataObject will be the script object
      //we loaded from the file

      %this.dataObject = %nso;
      
      //return the script object
      return %nso;
   }
   else
      echo("Script object from file ==> failed to load.");
   
   return -1;
}

Thank you elm,

So another quick question,

How would I check to see if the scriptobject was ever saved in the first place?
Like for the first time a client connects I need it to load a default set of vars