Hello Everyone,
I am trying to finish up my final assignment which is due in a few days and am confused on why the code I have is acting the way it is.
This is a list of variables I have initialized at the top of the class.
This code is ONLY part of a method, which works perfectly,
// for debugging ONLY System.out.println("Current Level # = " + level); System.out.println("Level Points = " + points); System.out.println("Total Points = " + totalPoints); System.out.println("Wolf's Found = " + userWolfCount); System.out.println("Sheep's Found = " + (level - 1)); System.out.println("Dog's Found = " + userDogCount); System.out.println("Total # of moves = " + playerMoveCount); System.out.println(); } // end of newGrid method
all variables above keeps perfect track of their values with no issues, I need to save the above variables to a CSV file, which I have written and it kind of works. Saves all values, except all values get recorded as '0'.
So I create a temporary method for debugging purposes, you will notice that they are identical.
The above is in the exact same class as the top code, but yet when I call the second code, (via a button on my GUI console), all values show as '0'.public void resume(){ System.out.println("\n***************************************"); System.out.println("Current Level # = " + level); System.out.println("Level Points = " + points); System.out.println("Total Points = " + totalPoints); System.out.println("Wolf's Found = " + userWolfCount); System.out.println("Sheep's Found = " + (level - 1)); System.out.println("Dog's Found = " + userDogCount); System.out.println("Total # of moves = " + playerMoveCount); System.out.println("***************************************\n"); }
I can not figure out why the variables are able to keep track in one method but not in the other.
Here is a representation of what my screen looks like.
1 2 3 4 5
1 * S * * *
2 * * * D *
3 * * * * *
4 * * * * *
5 * * * W *
Current Level # = 1
Level Points = 25
Total Points = 136
Wolf's Found = 1
Sheep's Found = 3
Dog's Found = 1
Total # of moves = 35
***************************************
Current Level # = 0
Level Points = 0
Total Points = 0
Wolf's Found = 0
Sheep's Found = -1
Dog's Found = 0
Total # of moves = 0
***************************************
BUILD SUCCESSFUL (total time: 1 minute 23 seconds)
Can someone explain to me why this is happening. I've been working on this assignment for 10-12 hours a day, for the last 8 days. Not sure if my mind is fried, or if I am just too tired to see the error.
Please help.