Im trying to make a hangman like game. When User enters a letter, if it corresponds with the correct letter in the word they are trying to guess, a debug log says “guessed right”. This is a chunk of the code thats suppose to do that:
However even though the letters match up in game, the debug log doesnt show up.
function CheckIfCorrect() {
splitWord = SplitString(word);
for(i = 0; i < splitWord.length; i++)
{
Debug.Log(underScore*);*
I would suggest cleaning this up. As @IgnoranceIsBliss said, strings can already be accessed as arrays. Therefore you can eliminate your SplitString function. Also, I’m assuming that underScore is the inputted letter? If so, your if statement would only return true if both indexes lined up in each array and were equal to each other. For example, if underScore = "a", and splitWord = "banana", checking for whether underScore _== splitWord* would not work because the index of “a” in underScore is 0 while the only a’s in splitWord are 1, 3, and 5. Therefore, you need to check if the element in splitWord is equal to underScore as a whole string. So like this:*_ function CheckIfCorrect() {
* for(i = 0; i < splitWord.Length; i++)* * {* _ if(splitWord == underScore)
* { Debug.Log(“Guessed Right”); } } listOfLetters.Clear(); }* This returns “Guessed Right” for me. Also, just in case that doesn’t work, ensure you’re actually calling your function. However I doubt that will be a problem. Hope that helped, Klep_