When I use the following code in Java 8 within NetBeans it doesn't seem to work well. For example, in one method I create the following:
boolean isGuessCorrect = true;
It is then passed to another method where it can be used. However, if I then have some conditional statement that changes the value it doesn't work. NetBeans actually tells me that it can't be changed. Instead I am forced to use something like this:
int isGuessCorrect = 1;
When I use that approach, treating 1 as true and 0 as false, I have no problems changing the values of the variables and passing them around as needed.
The problem is that, for readability, I would prefer using true/false rather than using digits to store the true/false conditions. Is there something special about them that keeps it from working the way I want?
EDIT: This is a very simple text based game that uses logical control of methods and passing variables to handle events in the game.
public static void main(String[] args)
{
//Sets the game status and difficulty.
//Using as a separate method so I don't have these variables overwritten on subsequent runs.
int newGame = 1;
int difficulty = 6;
game_menu1(newGame, difficulty);
}
The above is what I currently have to use, however, what I initially attempted was:
boolean newGame = true;
The idea is that, depending on if the game is new or not, different things would occur.
In a later part of the program:
public static void game_menu2(int newGame, int difficulty, int digit1, int digit2, int choice, int counter)
{
newGame = 0;
The above is what I am currently using. I change the 1 to 0 to indicate that the game is no longer new. However, if I used
public static void game_menu2(boolean newGame, int difficulty, int digit1, int digit2, int choice, int counter)
{
newGame = false;
It doesn't work. I'm sorry, but I would have to change a great deal more since I reference this in several places before I can get the exact error message.
EDIT 2: hmm. Even though I had the problem a few hours ago and last night, after changing the code to use boolean variables where needed I am not seeing the same error code. It's likely that the problem I had was something unrelated, a bug that just looked like it was an issue with boolean itself. It's also possible that I had a final operator in place previously where I am not currently using it. Even though I am very familiar with other languages, I am still learning Java in a classroom setting.
I would accept as a correct answer anyone that can show me the situations where this type of problem would normally be expected to occur.