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.
Loading

VulpesRank #55 · 29.2K reputationPosted Apr 30, 2011, 9:36 AM EDT
FroglegRank #1,020 · 1.9K reputationPosted Apr 29, 2011, 5:43 PM EDT
public void Save(string highScore)
{
using (StreamWriter sw = new StreamWriter("highScore.txt"))
{
sw.WriteLine(highScore);
}
}
Jamie Wyatt14 reputationPosted Apr 29, 2011, 5:57 PM EDT
Same error under the "Save" call.
Am I calling this wrong? I've got that method in and I'm calling it by typing highScore.Save("highScore.txt");
Many thanks for your help.
J
EDIT : I've attached the source code now, the method I'm talking about is in the "PlayScreen" class at the bottom.
FroglegRank #1,020 · 1.9K reputationPosted Apr 29, 2011, 7:20 PM EDT
if (keyState.IsKeyDown(Keys.F5))
{
Save(score);
}
and to save
public void Save(int highScore)
{
using (StreamWriter sw = new StreamWriter("highScore.txt"))
{
sw.WriteLine(Convert.ToString(highScore));
}
}
problem is as per your other post - you've got a hole in your bat
Jamie Wyatt14 reputationPosted Apr 30, 2011, 5:49 AM EDT
This is my load method:
public void Load(string highScoreString)
{
StreamReader sr = new StreamReader("highScore.txt");
highScoreString = sr.Readline();
sr.Close();
int loadedHighScore = int.Parse(highScoreString);
}
and I'm calling it in my update method with:
Load("highScore.txt");
As far as I can see the method is loading the string from the file but then won't parse it for some reason.
Ideally what I want it to do is grab the number from the file, parse it and then set that int as the highscore.
Thanks so much for your help so far!
J
Jamie Wyatt14 reputationPosted Apr 30, 2011, 6:11 PM EDT
Cheers for your help,
J.