Unreal crashes

when I press play unreal stops responding
this is the 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();

    SetupGame();

    PrintLine(TEXT("The hiddenWord is: %s."), *HiddenWord);
}

void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{
    if(bGameOver)
    {
        ClearScreen();
        SetupGame();
    }
    else
    {
        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"), HiddenWord.Len());
    PrintLine(TEXT("you have %i lives."), Lives);
    PrintLine(TEXT("Type in your guess \n press enter to continue..."));

    //const TCHAR HW[] = TEXT("plums");
    //PrintLine(TEXT("Character 1 of the hiddenword is: %c"), HiddenWord[0]);
    //PrintLine(TEXT("The 4th character of HW is: %c"), HW[3]);

    int32 i =0;
    while (i < 10)
    {
        PrintLine(TEXT("%i"), i);
    }

    for (int32 Index = 0; Index < 2; Index++)
    {
        PrintLine(TEXT("%i"), Index);
    }

    int32 j = 0;
    do
    {
        PrintLine(TEXT("%i"), j);
    } while (j < 2);
    

}

void UBullCowCartridge::EndGame()
{
    bGameOver = true;
    
    PrintLine(TEXT("\npress enter to play again."));
}


void UBullCowCartridge::ProcessGuess(FString Guess)
{
    if (Guess == HiddenWord)
    {
        PrintLine(TEXT("you have won"));
        EndGame();
        return;
    }

    

    if (Guess.Len() != HiddenWord.Len())
    {
        PrintLine(TEXT("The hidden word is %i letters long"), HiddenWord.Len());
        PrintLine(TEXT("Sorry, try guessing again \n You have %i lives remaining"), Lives);
        return;
    }
    if (!IsIsogram(Guess))
    {
        PrintLine(TEXT("No repeating letters, guess again"));
        return;
    }  
    // remove life
    PrintLine(TEXT("Lost a life"));
    --Lives;

    if (Lives <= 0)
    {
        ClearScreen();
        PrintLine(TEXT("You have no lives left!"));
        PrintLine(TEXT("the hidden word was: %s"), *HiddenWord);
        EndGame();
        return;
    }

    // show the player Bulls and Cows
    PrintLine(TEXT("Guess again, you have %i lives left"), Lives);

}

bool UBullCowCartridge::IsIsogram(FString Word) const
{
    return true;

}

Do you have a crash report

No I don’t because it just stops responding and I have to kill it from task manger, but when I reload it again it shows this message in message log load errors section.

Failed to load /Game/Levels/Level1_BuiltData.Level1_BuiltData Referenced by PersistentLevel

Can you compile your code directly in VS with CTRL + SHIFT + B (In windows)

Does your level open when you open your Editor?
This error seams to be a save issue, if your level is already saved, In the editor, you can try to duplicate it and move the original in a backup folder of your choice in your project Content directory. After Save All.

You can change the default map in Project Settings/ Map and Modes

I’m pretty sure @DanM could find the problem right away :grinning:

I tried it but it didn’t work, I appreciate your effort and I’m really thankful :black_heart: :black_heart:, guess I will wait for @DanM

Unreal Stops Responding Because Of This Infinite Loop

1st : While (i < 10) PrintLine() Here You Are Not Incrementing The Variable ‘i’ So PrintLine() Will Occur Infinite Number Of Times Because The Condition ( i < 10 ) Will Never False;

2nd : Same Thing You Did, Do This Things While Condition( j < 2) Is True. Here ‘j’ is Zero . And You Are Not Incrementing It, So It Will Be Always Zero.

2 Likes

oh I didn’t pay attention for the loops, that was a really dumb mistake, thanks bro that was helpful :black_heart: :black_heart: :black_heart:

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

Privacy & Terms