After modifying BullCowCartridge to add EndGame() function, the entire project crash after showing me the message of end game. I have tried to check where could it be the error but i can’t find out, google doesn’t seem to have an answer to this neither.
BullCowCartridge.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "BullCowCartridge.h"
#include <string>
void UBullCowCartridge::BeginPlay() // When the game starts
{
Super::BeginPlay();
ClearScreen();
PrintLine(TEXT("Preparado para jugar un poco\ncon el lenguaje?"));
PrintLine(TEXT("Recuerda no usar acentos,\nno queremos desperdiciar tinta en eso."));
SetupGame();
PrintLine(FString::Printf(TEXT("Tienes %i vidas"),PlayerLives));
FString StartMessage = FString::Printf(TEXT("Palabra de %i letras"), HiddenWord.Len());
FString InputQuestion = TEXT("¿Cuál es la palabra escondida?\nIntroduce tu respuesta:");
PrintLine(StartMessage);
PrintLine(InputQuestion);
}
void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{
/**
* GAME LOOP
*
* 1 Se establece la palabra secreta
* 2 Se da la pista sobre la palabra secreta
* 3 Se pide input
* 4 Se da feedback sobre la respuesta
* 5 Si es correcta ganas y si es incorrecta pierdes una vida
*
* **/
if (bGameOver)
{
BeginPlay();
}
else
{
ClearScreen();
if (Input == HiddenWord){
PrintLine(TEXT("Acertaste!"));
EndGame();
}else{
--PlayerLives;
if (PlayerLives > 0)
{
PrintLine(FString::Printf(TEXT("Oh... has fallado, te quedan %i intentos"), PlayerLives));
if (HiddenWord.Len()!=Input.Len())
{
PrintLine(FString::Printf(TEXT("La palabra solo tiene %i letras, intentalo de nuevo!"), HiddenWord.Len()));
}
}
else{
EndGame();
}
}
/**
* Check isogram
* check number of characters
*
* remove life
*
* check lifes > 0
* yes: Guessagain
* no: Mostrar respuesta y playAgain
*
* enter to playAgain
* check user input
* play again or quit
*
*
*
*
* */
}
}
void UBullCowCartridge::SetupGame()
{
HiddenWord = TEXT("Bufalo");
PlayerLives = HiddenWord.Len();
bGameOver = false;
}
void UBullCowCartridge::EndGame()
{
PrintLine(FString::Printf(TEXT("Has perdido, la palabra era %s\n pulsa ENTER para jugar de nuevo"), *HiddenWord));
bGameOver = true;
}
BullCowCartridge.h
// Fill out your copyright notice in the Description page of Project Settings.
#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();
// Your declarations go below!
private:
FString HiddenWord;
int32 PlayerLives;
bool bGameOver;
};
CrashLog
UE4Editor_Core
UE4Editor_Core
UE4Editor_Core
UE4Editor_Core
UE4Editor_Engine
UE4Editor_BullCowGame_6325!UCartridge::BeginPlay() [D:\VideoGamesProjects\BullCowGame-starter-kit\Source\BullCowGame\Console\Cartridge.cpp:11]
UE4Editor_BullCowGame_6325!UBullCowCartridge::BeginPlay() [D:\VideoGamesProjects\BullCowGame-starter-kit\Source\BullCowGame\BullCowCartridge.cpp:8]
UE4Editor_BullCowGame_6325!UTerminal::AcceptInputLine() [D:\VideoGamesProjects\BullCowGame-starter-kit\Source\BullCowGame\Console\Terminal.cpp:143]
UE4Editor_BullCowGame_6325!UTerminal::OnKeyDown() [D:\VideoGamesProjects\BullCowGame-starter-kit\Source\BullCowGame\Console\Terminal.cpp:112]
UE4Editor_BullCowGame_6325!TBaseUObjectMethodDelegateInstance<0,UTerminal,TTypeWrapper<void> __cdecl(FKey)>::Execute() [C:\FastEpicGamesLibrary\UE_4.22\Engine\Source\Runtime\Core\Public\Delegates\DelegateInstancesImpl.h:617]
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Core
UE4Editor_Core
UE4Editor_Core
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_UnrealEd
UE4Editor_UnrealEd
UE4Editor
UE4Editor
UE4Editor
UE4Editor
UE4Editor
kernel32
ntdll