Author Topic: Loading from file doesn´t work  (Read 1018 times)

I made a script that saves informations about players, things like money. That works fine. It saves the data in a file with the Blockland ID as name.
It is simply one number in the file, not more. When the player connects to the server, it should load his saved informations. But, you guessed it, it doesn´t work...
Code: [Select]
function GameConnection::onClientEnterGame(%this)
{
  %file = new FileObject();
  %file.openForRead("config/TestScript/"@%this.BL_ID@".txt");
  while(!%file.isEOF())
  {
    %line = %file.readLine();
    echo(%line);
  }
  if(%line $= "") { %this.pointsCount = 0; }
  else
    { %this.pointsCount = %line; }
  %file.close();
  %file.delete();
  messageClient(%this,'',"You have "@%this.pointsCount@" Points on this Server");
  parent::onClientEnterGame(%this);
}
What´s wrong?

Dont you need to package it.

It is only a small part of the script. Everything except this part works.

Code: [Select]
GameConnection::onClientEnterGame(%this)
{
  %file = new FileObject();
  %file.openForRead("config/TestScript/"@%this.BL_ID@".txt"); <<<<
  while(!%file.isEOF()) 
  {
    %line = %file.readLine();
    echo(%line);
  }
  if(%line $= "") { %this.pointsCount = 0; }
  else
    { %this.pointsCount = %line; }
  %file.close();
  %file.delete();
  messageClient(%this,'',"You have "@%this.pointsCount@" Points on this Server");
  parent::onClientEnterGame(%this);
}


You might have to return the parent function for it to work. So do you spawn?

Yep, that works. Oh, and the echo doesn´t return anything.

Woops my bad. So its still not working?

You might have to return the parent function for it to work. So do you spawn?
I´m confused... how do I return the parent function in the line you marked???

I´m confused... how do I return the parent function in the line you marked???

For the parent function just

return parent::onClientEnterGame(%this);

Ah, well. Now it works partly. Now I get "You have 0 Points on this Server". But the echo still returns nothing. The file exists and contains the number 6.

You know echo puts it into the consle right? So thats where your checking?

You know echo puts it into the consle right? So thats where your checking?
Of course I know...

Code: [Select]
GameConnection::onClientEnterGame(%this)
{
  %file = new FileObject();
  %file.openForRead("config/TestScript/"@%this.BL_ID@".txt");  //<<<< is this the right path for the file
  while(!%file.isEOF()) 
  {
    %line = %file.readLine();
    echo(%line);
  }
  if(%line $= "") { %this.pointsCount = 0; } //<<<<< becuase this makes me think that it is not working becuse it returns 0 you said
  else
    { %this.pointsCount = %line; }
  %file.close();
  %file.delete();
  messageClient(%this,'',"You have "@%this.pointsCount@" Points on this Server");
  parent::onClientEnterGame(%this);
}



So I am beging to think that it is not reading from the right file path, and thats why its not returning the 6.

I really don´t know whats wrong here. It´s like the file doesn´t exist...

If you're testing in single player your BL_ID is going to be 999999.

FUUUUUUUU....

Thank you, good to know^^

Now it works, thanks :)
« Last Edit: November 29, 2009, 04:31:43 PM by Gravity Cat »