HiddenWord is assigning to zero

Please don’t look too hard at the lack of comments. And don’t think too hard about the weird way I went about doing this.
So my game was working with zero issues so far, but my HiddenWord is changing to an empty string somewhere in here and I can’t figure out where.

// Fill out your copyright notice in the Description page of Project Settings.
#include "BullCowCartridge.h"

void UBullCowCartridge::BeginPlay() // When the game starts
{
    Super::BeginPlay();
    PrintLine(TEXT("The HiddenWord is: %s"), *HiddenWord); //for debug only, delete
    PrintLine(TEXT("Welcome To Bulls and Cows, The game that\nyou are somehow playing on a magical\nwooden board. Don't mind the Cowlords,\nthey're just watching you play. \nP.S. The Cowlords will be very angry if\nyou lose. Don't Make the Cowlords angry."));
    PrintLine(TEXT("Press Tab to type to the board"));
    PrintLine(TEXT("Press Enter to Begin"));
}

void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{
    ClearScreen();
    
    if (Input == HiddenWord)
    {
        PrintLine(TEXT("You Win!"));
        EndGame();
    }
    else
    {
        if (Input.Len() != HiddenWord.Len() && Input != "")
        {
            PrintLine(TEXT("The word is %i letters."), HiddenWord.Len());
        }
        else if (Input == "")
        {
            InitGame();
        }
        
        else
        {
            PrintLine(TEXT("Wrong. You are a Failure.\nGAME OVER"));
            EndGame();
        }
    }
} 
void UBullCowCartridge::InitGame()
{
    HiddenWord = TEXT("ccakke");
    Lives = HiddenWord.Len() + 1;
    bGameOver = false;
    PrintLine(TEXT("There is a %i letter word you need to guess\nGuess."), HiddenWord.Len());
}
void UBullCowCartridge::EndGame()
{
    bGameOver = true;
    PrintLine(TEXT("Press enter to play again."));
}

/* judge input for isogram/correctness
subtract lives
give feedback
kill if no more lives
continue if more lives
give bulls and cows
*/

I don’t think that code needs any personally. Comments should add value and I don’t think they would here, the code says enough.

Did it change to an empty string?

I think so… I can see it being initialized it the InitGame() function as “ccakke” (added extra letters to make sure everything was working properly), but I guess your question means I’m missing something?

Indeed. One more hint. Where are you printing the word and when are you calling InitGame?

Privacy & Terms