Problem in storeing highscore in xna gaming...:(
public void gethighscxore() { Boolean boolwork = true; fileread = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Read); scoreread = new StreamReader(fileread); for (int i = 0; i < maxhscore; i ) { texthscore1[i] = scoreread.ReadLine(); if (texthscore1[i] == null) { texthscore1[i] = "0"; } } scoreread.Close(); fileread.Close(); if (boolwork) { int j = 0; for (int i = 0; i < maxhscore; i ) { if (plane_.score > Convert.ToInt32(texthscore1[i])


VulpesRank #55 · 29.2K reputationPosted Feb 14, 2014, 10:32 AM EST
sachin patil57 reputationPosted Feb 15, 2014, 7:42 AM EST
FileStream fileread;
FileStream filewrite;
StreamReader scoreread;
StreamWriter scorewitte;
public void gethighscxore()
{
Boolean boolwork = true;
// create fo
fileread = new FileStream("ok.txt", FileMode.Open, FileAccess.Read);
scoreread = new StreamReader(fileread);
for (int i = 0; i < maxhscore; i++)
{
texthscore1[i] = scoreread.ReadLine();
if (texthscore1[i] == null)
{
texthscore1[i] = "0";
}
}
scoreread.Close();
fileread.Close();
if (boolwork)
{
int j = 0;
for (int i = 0; i < maxhscore; i++)
{
if (plane_.score > Convert.ToInt32(texthscore1[i]) && i == j)
{
texthscore2[i] = plane_.score.ToString();
i++;
if (i < maxhscore)
{
texthscore2[i] = texthscore1[j];
}
}
else
{
texthscore2[i] = texthscore1[j];
}
j++;
}
}
filewrite = new FileStream("ok.txt", FileMode.Create, FileAccess.Write);
scorewitte = new StreamWriter(filewrite);
for (int i = 0; i < maxhscore; i++)
{
scorewitte.WriteLine(texthscore2[i]);
}
scorewitte.Close();
filewrite.Close();
}
sir this is the proper code..this couch exception error,,,
System.MethodAccessException
i think ther is any problem in fileaccesing...
pls help me how can i resolve it
VulpesRank #55 · 29.2K reputationPosted Feb 15, 2014, 1:59 PM EST
http://stackoverflow.com/questions/20534714/methodaccessexception-for-streamreader-in-xna-windows-phone-app
sachin patil57 reputationPosted Feb 15, 2014, 7:38 PM EST
I THINK THERE IS ANY PROBLEM IN THE PROPERTIES OF TXT FILE AND PROJECT..COZ OF THIS ACCESS PROBLEM IS OCCURE.....
VulpesRank #55 · 29.2K reputationPosted Feb 16, 2014, 10:52 AM EST
Can you post the exact error message and are you able to pinpoint on which line it's occurring?
sachin patil57 reputationPosted Feb 17, 2014, 2:07 AM EST
i use IsolatedStorageFile instead of filestream...hurrry bt now one anoter problem is occuring..
that is....'System.FormatException'
in this typ of line in my code
int=convert.toint32(string);
...bt this error occure not always...
what should i do knw
VulpesRank #55 · 29.2K reputationPosted Feb 17, 2014, 2:39 AM EST
If you can't be sure what 'string' will contain, you could use this code instead:
string s = "12ab"; // or whatever
int i;
bool isValid = int.TryParse(s, out i);
if (isValid)
{
// do something with 'i'
}
else
{
// issue error message perhaps or, alternatively, proceed with i = 0
}
Notice that if the string can be parsed to an integer, int.TryParse returns true and the result is placed in the out paramater 'i'.
If it can't be parsed to an integer, int.TryParse returns false and a result of 0 is placed in the out parameter.
sachin patil57 reputationPosted Feb 17, 2014, 8:08 AM EST
{
texthscore2[i] = plane_.score.ToString();
i++;
if (i < maxhscore)
{
texthscore2[i] = texthscore1[j];
}
sir here the portion of game in which texthscore is string in plane.score is intiger....
I can only think that sometimes 'string' can be parsed to an integer (e.g. "123", "4567") and sometimes it can't (e.g. "12ab", "1,234").
as per this pera ...i cannot understnd that im only convert initiger value of score 123455 like..then how can it generate 12ass5......
n sir isn't posible to always convert corectly string to int.... confused,,,,blablblablaaba
VulpesRank #55 · 29.2K reputationPosted Feb 17, 2014, 9:27 AM EST
Is that number being entered in a text box and, if it is, are you performing any manipulations on it before Convert.ToInt32 is being called?
sachin patil57 reputationPosted Feb 18, 2014, 4:56 AM EST
VulpesRank #55 · 29.2K reputationPosted Feb 18, 2014, 10:52 AM EST