Here is my code:
Inside the methods to read and write I have error messages set up in case something goes wrong, but other than that they are exactly the same as File.Read/Write methods.
I need the badGame = -1; to run, and I can get it to run with the code that I set. However, since I have spent a while on this issue and only finding a solution by thinking of trying something different for no other reason as to understand why a line of code will not read and get's hopped over, I would like to know why so that I can avoid things like this in the future. It's bad enough to look for your mistakes and fix them. It gets impossible to carry on after a while when you will never know if an error is yours or if the software happens to have a kink. Maybe that kink happens to someone else after they use it and no me. A random line of code skipped for no real logical reason is not great.
So can someone enlighten me why first writing and then reading the same data will run the next line of code, but if I use array = array2, the line after it will not run. Thanks!
P.S If I seem frustrated it's because I want to be able to trust a language in simple things like this. If I can't, and I spend hours looking for an error that I didn't even make, it's going to affect my state of mind and my workflow. I could have probably published what I have made by now not to mention going to sleep or doing other things if I wasn't trying to figure this out.
How common is this with programming in general. Do things often not work sometimes for no clearly apparent reason?
EDIT: When I debug it, badGame shows up as -1 everywhere as a console write. However, the code doesn't seem to care and keeps going on like it's not -1. At some point it showed up as 0, which now didn't happen as I kept writign it to console at every possible turn.
C#:
//Version that reads badGame = -1,
//fileData = new string[lengthArray];
//fileData = fileDataFixed;
FileWriteLines(pathGames, fileDataFixed);
fileData = FileReadLines(pathGames);
badGame = -1;
//Versions that do not read the line
//1
badGame = -1;
//fileData = new string[lengthArray];
fileData = fileDataFixed;
//FileWriteLines(pathGames, fileDataFixed);
//fileData = FileReadLines(pathGames);
//2
//fileData = new string[lengthArray];
fileData = fileDataFixed;
//FileWriteLines(pathGames, fileDataFixed);
//fileData = FileReadLines(pathGames);
badGame = -1;
//3
fileData = new string[lengthArray];
fileData = fileDataFixed;
//FileWriteLines(pathGames, fileDataFixed);
//fileData = FileReadLines(pathGames);
badGame = -1;
//4
badGame = -1;
fileData = new string[lengthArray];
fileData = fileDataFixed;
//FileWriteLines(pathGames, fileDataFixed);
//fileData = FileReadLines(pathGames);
Inside the methods to read and write I have error messages set up in case something goes wrong, but other than that they are exactly the same as File.Read/Write methods.
I need the badGame = -1; to run, and I can get it to run with the code that I set. However, since I have spent a while on this issue and only finding a solution by thinking of trying something different for no other reason as to understand why a line of code will not read and get's hopped over, I would like to know why so that I can avoid things like this in the future. It's bad enough to look for your mistakes and fix them. It gets impossible to carry on after a while when you will never know if an error is yours or if the software happens to have a kink. Maybe that kink happens to someone else after they use it and no me. A random line of code skipped for no real logical reason is not great.
So can someone enlighten me why first writing and then reading the same data will run the next line of code, but if I use array = array2, the line after it will not run. Thanks!
P.S If I seem frustrated it's because I want to be able to trust a language in simple things like this. If I can't, and I spend hours looking for an error that I didn't even make, it's going to affect my state of mind and my workflow. I could have probably published what I have made by now not to mention going to sleep or doing other things if I wasn't trying to figure this out.
How common is this with programming in general. Do things often not work sometimes for no clearly apparent reason?
EDIT: When I debug it, badGame shows up as -1 everywhere as a console write. However, the code doesn't seem to care and keeps going on like it's not -1. At some point it showed up as 0, which now didn't happen as I kept writign it to console at every possible turn.
C#:
public static string[] FileReadLines(string pathFile)
{
if (File.Exists(pathFile))
{
string[] txt = File.ReadAllLines(pathFile);
return txt;
}
else
{
Message("Read lines failed: File doesn't exist.");
string[] txt = { "error" };
Timer();
return txt;
}
}
public static void FileWriteLines(string pathFile, string[] txtArray)
{
if (File.Exists(pathFile))
{
File.WriteAllLines(pathFile, txtArray);
}
else
{
Message("Creating new file..");
File.WriteAllLines(pathFile, txtArray);
}
Last edited: