Insurance against game crash if there is no word file

Fix in BeginPlay

void UBullCowCartridge::BeginPlay() // When the game starts
{
    Super::BeginPlay();
    
    const FString WordListPath = FPaths::ProjectContentDir() / TEXT("WordLists/HiddenWordList.txt");
    FFileHelper::LoadFileToStringArrayWithPredicate(Isograms, *WordListPath, [](const FString Word)
    {
        return Word.Len() >= 4 && Word.Len() <= 8 && IsIsogram(Word);
    });
    
    if (Isograms.Num() != 0)
    {
        SetupGame(); //Setting Up Game
    }
    else
    {
        WordsFileMissing = true;
        PrintLine(TEXT("File HiddenWordList.txt are missing"));
    }
}

Fix in OnInput

void UBullCowCartridge::OnInput(const FString& PlayerInput) // When the player hits enter
{
    if (!WordsFileMissing)
    {
        if (bGameOver)
        {
            ClearScreen();
            SetupGame();
        }
        else
        {
            ProcessGuess(PlayerInput);
        } 
    }
}

1 Like

Coming along nicely

Privacy & Terms