Help needed with This code

This is my Code I checked everything according to the lecture but I am not getting the same result in the game as it is shown in the lecture i.e. when after every right and wrong answer the screen is not cleared. when I win the and as the code suggest that I have to press enter to play again and when presses it directly takes me to the output of wrong guess as shown in the screenshot I uploaded.
Image 1. After correct guess
Image 2.When enter is presses after the correct guess //directly the output of wrong guess
Please help me with this

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

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

  PrintLine(TEXT("The Hidden Word is: %s. "), *HiddenWord); // Debug Line
   
}

void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{
  
  if (bGameOver)
  {
    ClearScreen();
    SetupGame();
  }
  else   //  Checking PlayerGuess
  {
    
}
  
  PrintLine(Input);
  if  (Input == HiddenWord)
  {
    PrintLine(TEXT("Congratulations! You Win."));
    EndGame();
  } 
  else
  {
    if (Input.Len() != 4 )
    {
      PrintLine(TEXT("There are only %i characters in the Hidden Word.\nYou have Lost!"), HiddenWord.Len()); 
      EndGame(); 
    }

  }
    
}
  // Check if it is Isogram
  // Prompt To Guess Again
  // Check number of characters
 // Prompt to Guess again

  // Remove Life                                                                                    
  
  // Check if lives > 0
  // If yes TryAgain
  // Show lives left
  // If no GameOver and HiddenWord
  // Promt To Play Again, Press Enter to Play Again?
  // Check User Input
  // TryAgain or Quit  

  
void UBullCowCartridge::SetupGame()
{
 // Welcoming the Player
    PrintLine(TEXT("Hello Kids! Welcome to the Bull Cows game."));
    HiddenWord = TEXT("Adesh");  
    Lives = 3;
    bGameOver = false;
    PrintLine(TEXT("Guess the %i letter word!"), HiddenWord.Len()); 
    PrintLine(TEXT("Type your answer and Press Enter.."));
}

void UBullCowCartridge::EndGame()
{
  bGameOver = true;
  PrintLine(TEXT("Press Enter to Play Again.."));
}

Please indent your code correctly. Doing so should make it more obvious as to what the issue is

void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{  
    if (bGameOver)
    {
        ClearScreen();
        SetupGame();
    }
    else   //  Checking PlayerGuess
    {
    }
    PrintLine(Input);
    if  (Input == HiddenWord)
    {
        PrintLine(TEXT("Congratulations! You Win."));
        EndGame();
    } 
    else
    {
        if (Input.Len() != 4 )
        {
            PrintLine(TEXT("There are only %i characters in the Hidden Word.\nYou have Lost!"), 
            HiddenWord.Len()); 
            EndGame(); 
        }
    }
}

This is my code

  • The screen is not cleared after pressing enter.
    The screen must clear after I Press Enter to Play Again.

Do you see an issue with lines 22-25?

Thank you @DanM . The problem is solved. :slight_smile:

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

Privacy & Terms