Hello Everyone!
I passed the lesson # 60. Booleans in course “Unreal Engine C++ Developer” and faced the following issue:
When I type the incorrect word with the incorrect letters number, my Unreal crushes.
But the game’s behaviour meet expectations when I type the correct word or incorrect word with correct letters number.
Please see my code below and the screenshot from Unreal Error when it suggest to restart the game after crush.
// 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 HiddenWord is: %s."), *HiddenWord); // Debug Line
}
void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{
if (bGameOver)
{
ClearScreen();
SetupGame();
}
else // Checking PlayerGuess
{
if (Input == HiddenWord)
{
PrintLine(TEXT("You have won!"));
EndGame();
}
else
{
if (Input.Len() != HiddenWord.Len())
{
PrintLine(TEXT("The Hidden Word is %s charachters long. \nYou have lost!"), HiddenWord.Len());
EndGame();
}
}
}
// Check If Isogram
// Prompt to Guess Again
// Check Rught Number Characters
// Prompt to Guess Again
// Remove Life
// Chck if Lives > 0
// If yes GuessAgain
// Show Lives Left
// If No Show GameOver and HiddenWord?
// Prompt to play again, Press Enter to Play Again
// Check User Input
// PlayAgain or Quit
}
void UBullCowCartridge::SetupGame()
{
// Welcoming the player
PrintLine(TEXT("Hi! Welcome to the Bull Cows Game!"));
HiddenWord = TEXT("cakes");
Lives = 4;
bGameOver = false;
PrintLine(TEXT("Guess the %i letter word"), HiddenWord.Len());
PrintLine(TEXT("Type in your guess. \nPress Enter to Continue...")); // Prompt player for guess
}
void UBullCowCartridge::EndGame()
{
bGameOver = true;
PrintLine(TEXT("Press enter to play again."));
}