So basically im doing a hangman game printing the results directly on the console. Ive got everything working, last step is printing my array variable m_WordToDisplay which contains all of the guessed letters with the underscores for the spaces not guessed yet.
Every time the user makes a correct guess, i want to debug.log or print m_WordToDisplay, but when i do so, what it reads on the console instead of the actual word (ie. w__d), instead it reads System.Char
I know my variable m_WordToDisplay has the word stored in it because when i step into the code i see the guessed letter and the underscores. so the problem seems to really be just when printing the actual result. Here is my code which is relevant:
private char[] m_WordToDisplay;
My initialize method where i choose the word and then fill in the array with underscores:
public void InitializeGame (Player player, int numberOfMistakesAllowed = 6){
if (player == null){
Debug.Log ("ma player is null");
}
if (m_numberOfMistakesAllowed < 0){
Debug.Log ("number of mistakes must be non negative");
}
m_Player = player;
LoadWordList();
m_numberOfMistakesAllowed = numberOfMistakesAllowed;
Outcome = Outcome.InProgress;
Word = ChooseWord ();
m_WordToDisplay = new char [this.Word.Length];
for (int i = 0; i < m_WordToDisplay.Length; i++){
m_WordToDisplay *= ('_');*
-
}*
My guess method to pass in the letter chosen by the user:
-
public void Guess (char letter){*
-
if (Outcome != Outcome.InProgress)* -
Debug.Log ("Game is not in progress");* -
if (m_GuessedAlready.Contains(letter)){* -
print("You already guessed that letter, dummy");* -
return;* -
}* -
m_GuessedAlready.Add(letter);* -
if (!Word.Contains(letter)){* -
print("There is no" + letter);* -
m_IncorrectGuesses += 1;* -
if (m_IncorrectGuesses > m_numberOfMistakesAllowed){* -
Outcome = Outcome.Loss;* -
print ("You lost"); * -
}* -
else{* -
print ("Number of guesses left: " + MistakesRemaining());* -
}* -
}* -
else{* -
FillInCorrectGuess(letter);* -
Debug.Log (m_WordToDisplay); // THIS HERE DOESNT PRINT THE WORD WITH THE GUESSED LETTERS BUT INSTEAD System.Char[]* -
}*
and finally, here is my method where i fill in every letter in the word with the guessed letter when its a letter that is part of the word
- private void FillInCorrectGuess (char letter){*
-
for (int i = 0; i < Word.Length; i++){*
_ if (Word == letter)_
m_WordToDisplay = letter;
* }*
*So yeah, all i want to do ideally would be something like *
Debug.Log ("Good guess! " + m_WordToDisplay);
But doing so prints “Good guess! System.Char[]”
Thanks in advance anyone