The hiddenword doesn't appers in ue4

So i’m at the Random and ue4 docs video but for some reason ue4 doesn’t want to display the hiddenword. As i can see my code is the same as in the video but maybe i missed something!
Here’s the code from BullCowCartridge.cpp:

#include "BullCowCartridge.h"
#include "HiddenWordList.h"
//#include "Math/UnrealMathUtility.h"

void UBullCowCartridge::BeginPlay() // When the game starts
{
    Super::BeginPlay();
    //PrintLine(TEXT("%i"), FMath::RandRange(0, 10));
   
    SetupGame();// Setting up the game(Calling the function)
    PrintLine(TEXT("The number of possible words is %i"),Words.Num());
    PrintLine(TEXT("The number of valid words is:%i."),  GetValidWords(Words).Num());
    PrintLine(TEXT("ValidWords -1 is: %i."),GetValidWords(Words).Num() -1);
   
}
void UBullCowCartridge::OnInput(const FString& PlayerInput) // When the player hits enter
{
    if (bGameOver)
    {
        ClearScreen();
        SetupGame();
    }
    else // Checking Player Guess
    {
        ProcessGuess(PlayerInput);
    }
}
   
void UBullCowCartridge::SetupGame() // What the function is doing.
{
    // Welcoming the player
    PrintLine(TEXT("Welcome to the game!"));
    HiddenWord = GetValidWords(Words)[FMath::RandRange(0, GetValidWords(Words).Num() -1)];
    Lives = HiddenWord.Len();// Set Lives
    bGameOver = false;
    PrintLine(TEXT("Guess the %i letter word."), HiddenWord.Len());
    PrintLine(TEXT("You have %i lives left."), Lives);
    PrintLine(TEXT("Type in your guess and  \npress enter to continue...")); // Prompt player to guess!
}
void UBullCowCartridge::EndGame()
{
    bGameOver = true;
    PrintLine(TEXT("\nPress enter to play again."));
   
}
void UBullCowCartridge::ProcessGuess(const FString& Guess)
{
   
    if (Guess == HiddenWord)
    {
        PrintLine(TEXT("You've won!"));
        EndGame();
        return;
    }
   
    // // Check If it's an Isogram
    if (!IsIsogram(Guess))
    {
        PrintLine(TEXT("No repeating letters, guesss again."));
        return;
    }
   
    if( Guess.Len() != HiddenWord.Len())
            {
                 PrintLine(TEXT("The HiddenWord is %i letters long"), HiddenWord.Len());
                PrintLine(TEXT("Sorry, try guessing again! \nYou have %i lives left"), Lives);
                return;
            }
    // Remove the Life
    PrintLine(TEXT("Lost a life!"));
    --Lives;
    // Check if lives > 0
     if (Lives <= 0)
        {
            ClearScreen();
            PrintLine(TEXT("You have no lives left!"));
            PrintLine(TEXT("The hidden word was:%s" ), *HiddenWord);
            EndGame();
            return;
        }
   
    // Show the player the bulls and cows
    PrintLine(TEXT("Gues again, you have %i lives left"), Lives);
}
bool UBullCowCartridge::IsIsogram(const FString& Word) const
{
    for (int32 Index = 0; Index < Word.Len(); Index++)
    {
        for (int32 Comparison = Index + 1; Comparison < Word.Len(); Comparison++)
        {
            if (Word[Index] == Word[Comparison])
            {
                return false;
            }
           
        }
       
    }
   
    return true;
}
TArray<FString>UBullCowCartridge::GetValidWords(const TArray<FString>& WordList) const
{
TArray<FString> ValidWords;
for (FString Word : WordList)
{
    if (Word.Len() >= 4 && Word.Len() <=8 && IsIsogram(Word))
    {
        ValidWords.Emplace(Word);
    }
}
return ValidWords;
}

BullCowCartridge.h:

#pragma once
#include "CoreMinimal.h"
#include "Console/Cartridge.h"
#include "BullCowCartridge.generated.h"
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class BULLCOWGAME_API UBullCowCartridge : public UCartridge
{
    GENERATED_BODY()
    public:
    virtual void BeginPlay() override;
    virtual void OnInput(const FString& Input) override;
    void SetupGame();
    void EndGame();
    void ProcessGuess(const FString& Guess);
    bool IsIsogram(const FString& Word) const;
    TArray<FString> GetValidWords(const TArray<FString>& WordList)const;
    // Your declarations go below!
    private:
    FString HiddenWord;
    int32 Lives;
    bool bGameOver;
};

and finally a screenshot of ue4:


Can somebody pls help?

Where do you print it?

Also in the future please use a code block by using the </> button. Also please indent your code correctly.

Line 16
PrintLine(TEXT(“The number of valid words is:%i.”), GetValidWords(Words).Num());

That prints the number of valid words, words that are isograms and of the correct length.

Your screenshot shows that that number is 513.

oh yeah now i see that i’ve deleted a line that michael uses!

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms