Help. Not working conditions

Hello. I have a problem with compiling. Unreal Engine not see my conditions, but compiling is successfully
It’s header

#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(FString Guess);
	bool IsIsogram(FString Word) const;
	// Your declarations go below!
	private:
		FString HiddenWord;
		FString AgainYes, AgainNo;
		int32 Lives;
		bool bGameOver;
	
};

It’s cpp file

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

void UBullCowCartridge::BeginPlay() // When the game starts
{
    Super::BeginPlay();
    SetupGame();
}

void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{
    if (bGameOver) 
    {
        ClearScreen();
        SetupGame();
    }
    else // Checking PlayerGuess
    {
        ProcessGuess(Input);     
    }
}
void UBullCowCartridge::SetupGame()
{
    PrintLine(TEXT("Welcome to Bull Cows!"));

    HiddenWord = TEXT("cakes");  
    Lives = HiddenWord.Len(); 
    bGameOver = false;

    PrintLine(TEXT("Guess the %i letter word!\nYou have %i Lives"), HiddenWord.Len(), Lives);
    PrintLine(TEXT("Press <Tab> and type your guess,\nthen press <Enter> to continue...."));   
    IsIsogram(HiddenWord);
}

void UBullCowCartridge::EndGame() {
    bGameOver = true;
    PrintLine(TEXT("Press enter to play again"));
}
bool UBullCowCartridge::IsIsogram(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;
}
void UBullCowCartridge::ProcessGuess(FString Guess)
{
    if (Lives <= 0) 
    {
        ClearScreen();
        PrintLine(TEXT("You have no lives left!"));
        EndGame();
        return;
    }
    if (Guess == HiddenWord)
    {
        PrintLine(TEXT("You've Won!"));
        EndGame();
        return;
    }
    if (!IsIsogram(Guess)) 
    {
        PrintLine(TEXT("No repeating letters, guess again"));
        return;
    }
    if (Guess != HiddenWord)
    {
        ClearScreen();
        PrintLine(TEXT("Sorry, but is wrong, try again!"));
        PrintLine(TEXT("Lives: %i"), Lives--);
        return;

    }
    if (Guess.Len() != HiddenWord.Len())
    {
        PrintLine(TEXT("The Hidden Word is %i characters long.\nYou have lost!"), HiddenWord.Len());
        PrintLine(TEXT("Lives: %i"), Lives--);
        return;
    }

}
   

I’m checking condition of Guess(it’s what we input) length here , but that not working


Must be output this
if (Guess.Len() != HiddenWord.Len())
{
PrintLine(TEXT(“The Hidden Word is %i characters long.\nYou have lost!”), HiddenWord.Len());
PrintLine(TEXT(“Lives: %i”), Lives–);
return;
}

if (Guess != HiddenWord)
{
    ClearScreen();
    PrintLine(TEXT("Sorry, but is wrong, try again!"));
    PrintLine(TEXT("Lives: %i"), Lives--);
    return;
}

Because of this. This will always happen when the guess wasn’t correct, anything after this isn’t executed.

1 Like

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

Privacy & Terms