Jamie Wyatt

Jamie Wyatt

  • NA
  • 14
  • 10.4k

Saving an int to a txt file

Apr 29 2011 8:51 PM
Evening all, having a bit of an issue with a game I'm making. As it stands the game will record your score, and update a high score integer if your score is higher than the current high score.

What I'm trying to do is make a couple of Save / Load methods that will save the highscore when the game is over and re load it when the game is opened again. 

I'm trying to do this by just writing the number to a txt file and then reading it back in but I can't get it to work.

The method is: 

public void Save(string highScore)
{
highScore.ToString();
System.IO.TextWriter textOut = null;
textOut = new System.IO.StreamWriter(highScore);
Save("highScore.txt");
}

and I'm calling it by using :

highScore.Save("highScore.txt");

But I get red lines under the "Save" on the method call saying " 'int' does not contain a defenition for 'Save' and no extension method 'Save' accepting a first agrument of type 'int' could be found"

I've tried calling ToString outside of the method before it is called as well but I had the same problem.

Any help would be great.

Cheers.




Answers (6)