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])

VulpesPosted Feb 18, 2014, 3:52 PM
sachin patilPosted Feb 18, 2014, 9:56 AM
VulpesPosted Feb 17, 2014, 2:27 PM
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 patilPosted Feb 17, 2014, 1:08 PM
{
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
VulpesPosted Feb 17, 2014, 7:39 AM
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 patilPosted Feb 17, 2014, 7:07 AM
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
VulpesPosted Feb 16, 2014, 3:52 PM
Can you post the exact error message and are you able to pinpoint on which line it's occurring?
sachin patilPosted Feb 16, 2014, 12:38 AM
I THINK THERE IS ANY PROBLEM IN THE PROPERTIES OF TXT FILE AND PROJECT..COZ OF THIS ACCESS PROBLEM IS OCCURE.....
VulpesPosted Feb 15, 2014, 6:59 PM
http://stackoverflow.com/questions/20534714/methodaccessexception-for-streamreader-in-xna-windows-phone-app
sachin patilPosted Feb 15, 2014, 12:42 PM
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
VulpesPosted Feb 14, 2014, 3:32 PM