I am having an issue with Unreal engine

When I play enter once I have the guess, the editor crashes.
Code:

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

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

    InitGame();// Setting up the game

}

void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{
    
    if (bGameOver)
    {
        ClearScreen();
        InitGame();
    }
    else
    {
        if (Input == HiddenWord)
        {
            PrintLine(TEXT("Yo guessed. Congrats !"));


            EndGame();
        }
        else
        {

            Lives--;

            if (HiddenWord.Len() != Input.Len())
            {
                PrintLine(TEXT("The word is %i letters long"), HiddenWord.Len());

            }
            if (Lives == 0)
            {
                PrintLine(TEXT("Yo din not guess. Try again."));
                EndGame();
            }

        }

        if (HiddenWord.Len() != Input.Len())
        {
            PrintLine(TEXT("The word is %s letters word"), HiddenWord.Len()); ;
        }
    }

   

}   
void UBullCowCartridge::InitGame()
{
    // Welcoming the player
    PrintLine(TEXT("Welcome to Bull Cow Game ! "));
    HiddenWord = TEXT("Cake");
    Lives = 4;
    PrintLine(TEXT("You have %i lives"), Lives);
    PrintLine(TEXT("Guess the %i letters word"), HiddenWord.Len());
    PrintLine(TEXT("Type your guess\npress enter to continue..."));
     
    bGameOver = false; 
}

void UBullCowCartridge::EndGame()
{
    bGameOver = true;  
    PrintLine(TEXT("Press enter to play again."));
}`
// 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 InitGame();
	void EndGame();


	// Your declarations go below!
	private:
	FString HiddenWord;
	int32 Lives;
	bool bGameOver;
};

Hi friend - so I believe your issue is on this line

PrintLine(TEXT(“The word is %s letters word”), HiddenWord.Len()); ;

you have two ;; at the end, and also the wrong format specifier. It has to be %i since Len() returns an integer.

Hope this helps,

Cheers!

Thanks, that was the issue !

1 Like

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

Privacy & Terms