Cannot Launch Bull Cows Game

I am unable to launch the final Bull Cows Game. I made a couple of tweaks, and I can compile them and run in the engine. When I try to run I get this error:

BC

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

void UBullCowCartridge::PrintHead(){
    ClearScreen();
    PrintLine(TEXT("Welcome to the Bull Cows game!"));
    PrintLine(TEXT("Guess the %i letter word."), HiddenLength);
    PrintLine(TEXT("You have %i lives."), Lives);
}

void UBullCowCartridge::BeginPlay() // When the game starts
{
    Super::BeginPlay();
    //Fill the list with words
    const FString WordListPath = FPaths::ProjectContentDir() / TEXT("WordLists/HiddenWordList.txt");
    TArray<FString> StartWords;
    FFileHelper::LoadFileToStringArray(StartWords, *WordListPath);
    GetValidWords(StartWords);

    //test function to print words and length
    // PrintLine(TEXT("%i"), Words.Num());
    // for(int32 j=0;j<5;j++){
    //     PrintLine(TEXT("%s"), *Words[j]);
    // }
    InitGame();
}

void UBullCowCartridge::GetValidWords(const TArray<FString>& StartWords){
    for(FString Word : StartWords){
        if(IsIsogram(Word) && Word.Len() > 3 && Word.Len() < 6){
            Words.Emplace(Word);
        }
    }
}

void UBullCowCartridge::InitGame(){
    
    GetWord(Words);
    Lives = HiddenWord.Len();
	HiddenLength = HiddenWord.Len();
    bGameOver = false;
    Board = "";
    for(int32 i=0;i<HiddenWord.Len();i++){
        Board.Append("_");
    }
    PrintHead(); 
}

void UBullCowCartridge::GetWord(const TArray<FString>& Words){
    
    HiddenWord = Words[FMath::RandRange(0, Words.Num()-1)];
}

void UBullCowCartridge::EndGame(){
    
    Lives = 0;
    PrintLine(TEXT("Press Enter to play again."));
    InitGame();
}

void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{
    const FString& GuessWord = Input;
    if(bGameOver){
        ClearScreen();
        EndGame();
    }
    else{
        ClearScreen();
        ProcessGuess(GuessWord, Lives);
    }
}

bool UBullCowCartridge::IsIsogram(const FString& GuessWord) const
{
    for(int32 i=0;i<GuessWord.Len()-1;i++){
        for(int32 j=0;j<GuessWord.Len()-1;j++){
            if(GuessWord[i] == GuessWord[j] && i != j){
                return false;
            }
        }
    }
    return true;
}

void UBullCowCartridge::ProcessGuess(const FString& GuessWord, int32 Counter){
    ClearScreen();
    if(GuessWord.ToLower() == HiddenWord.ToLower()){
        PrintLine(TEXT("You Win!"));
        PrintLine(TEXT("Press Enter to Play Again"));
        bGameOver = true;
        return;
    }
    if(Lives <= 0){
        ClearScreen();
        PrintLine(TEXT("You have no lives left."));
        PrintLine(TEXT("The hidden word was %s."), *HiddenWord);
        PrintLine(TEXT("Press Enter to Play Again"));
        bGameOver = true;
        return;
    }   
    
    PrintLine(TEXT("You have %i lives left."), Lives);
    PrintLine(TEXT("The Word is %s"), *HiddenWord);
    --Lives;
    //start checks
    if(GuessWord.Len() != HiddenWord.Len()){
        PrintLine(TEXT("Your word was not long enough"));
        PrintLine(TEXT("The word is %i letters long"), HiddenWord.Len());
        PrintLine(TEXT("The Board is %s"), *Board);
        return;
    }
    // if(!IsIsogram(GuessWord)){
    //     PrintLine(TEXT("No repeating letters allowed!"));
    //     PrintLine(TEXT("The word is %i letters long"), HiddenWord.Len());
    //     PrintLine(TEXT("The Board is %s"), *Board);
    //     return;
    // }
    for(int32 i=0;i<HiddenWord.Len();i++){
        if(GuessWord[i] == HiddenWord[i]){
            Board[i] = GuessWord[i];
        }
    }
    PrintLine(TEXT("You enterd an incorrect word"));
    PrintLine(TEXT("The word is %i letters long"), HiddenWord.Len());
    PrintLine(TEXT("The Board is %s"), *Board);
}

Are you sure Words is being populated?

I believe it is. When I run the following code it produces output on the console screen in the game.

void UBullCowCartridge::BeginPlay() // When the game starts
{
    Super::BeginPlay();
    //Fill the list with words
    const FString WordListPath = FPaths::ProjectContentDir() / TEXT("WordLists/HiddenWordList.txt");
    TArray<FString> StartWords;
    FFileHelper::LoadFileToStringArray(StartWords, *WordListPath);
    GetValidWords(StartWords);

    //test function to print words and length
    PrintLine(TEXT("%i"), Words.Num());
    for(int32 j=0;j<5;j++){
        PrintLine(TEXT("%s"), *Words[j]);
    }
    //InitGame();
}

consolesnip.PNG

Not seeing the error. Could you show the crash report?

Hello, I have uploaded the logs here:


thanks for your help. Everything was going fine until the final attempt to launch to windows.

That doesn’t show a crash but a compilation error

Building 5 actions with 12 processes...
  [1/5] BullCowCartridge.cpp
   C:\Users\joshu\Desktop\Projects\C++ Unreal\BullCowGame-starter-kit\Source\BullCowGame\BullCowCartridge.cpp(27) : error C2014: preprocessor command must start as first nonwhite space
   C:\Users\joshu\Desktop\Projects\C++ Unreal\BullCowGame-starter-kit\Source\BullCowGame\BullCowCartridge.cpp(28) : error C2059: syntax error: 'for'
   C:\Users\joshu\Desktop\Projects\C++ Unreal\BullCowGame-starter-kit\Source\BullCowGame\BullCowCartridge.cpp(28) : error C2143: syntax error: missing ')' before ';'
   C:\Users\joshu\Desktop\Projects\C++ Unreal\BullCowGame-starter-kit\Source\BullCowGame\BullCowCartridge.cpp(28) : error C2065: 'i': undeclared identifier
   C:\Users\joshu\Desktop\Projects\C++ Unreal\BullCowGame-starter-kit\Source\BullCowGame\BullCowCartridge.cpp(28) : error C2039: 'Len': is not a member of 'TArray<FString,FDefaultAllocator>'
  C:\Program Files\Epic Games\UE_4.22\Engine\Source\Runtime\Core\Public\GenericPlatform/GenericPlatformMisc.h(792): note: see declaration of 'TArray<FString,FDefaultAllocator>'
   C:\Users\joshu\Desktop\Projects\C++ Unreal\BullCowGame-starter-kit\Source\BullCowGame\BullCowCartridge.cpp(28) : error C2059: syntax error: ')'
   C:\Users\joshu\Desktop\Projects\C++ Unreal\BullCowGame-starter-kit\Source\BullCowGame\BullCowCartridge.cpp(29) : error C2065: 'i': undeclared identifier
   C:\Users\joshu\Desktop\Projects\C++ Unreal\BullCowGame-starter-kit\Source\BullCowGame\BullCowCartridge.cpp(29) : error C2059: syntax error: ';'
   C:\Users\joshu\Desktop\Projects\C++ Unreal\BullCowGame-starter-kit\Source\BullCowGame\BullCowCartridge.cpp(31) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
   C:\Users\joshu\Desktop\Projects\C++ Unreal\BullCowGame-starter-kit\Source\BullCowGame\BullCowCartridge.cpp(32) : error C2059: syntax error: '}'
   C:\Users\joshu\Desktop\Projects\C++ Unreal\BullCowGame-starter-kit\Source\BullCowGame\BullCowCartridge.cpp(32) : error C2143: syntax error: missing ';' before '}'
   C:\Users\joshu\Desktop\Projects\C++ Unreal\BullCowGame-starter-kit\Source\BullCowGame\BullCowCartridge.cpp(34) : error C2143: syntax error: missing ';' before '{'
   C:\Users\joshu\Desktop\Projects\C++ Unreal\BullCowGame-starter-kit\Source\BullCowGame\BullCowCartridge.cpp(34) : error C2447: '{': missing function header (old-style formal list?)
  [2/5] BullCowCartridge.gen.cpp

I think that may have been the wrong log for what I was looking at. I am not getting a compilation error on my end. When I click the launch button on windows the entire process goes through, then the window pops up and gives that error. I looked in the output log and it said to look in the location C:\Users\joshu\AppData\Roaming\Unreal Engine\AutomationTool\Logs\C+Program+Files+Epic+Games+UE_4.22
I uploaded the log.txt file from there to the dropbox for you to look at. It looks like that log is being created when I run the launch command.
Also, Unreal Engine does not crash; just the window that results from clicking launch.

Error: Assertion failed: (Index >= 0) & (Index < ArrayNum) [File:Runtime\Core\Public\Containers/Array.h] [Line: 611]
Error: Array index out of bounds: 0 from an array of size 0

Launch is using a packaged version of the game. Did you add the word lists folder to the Non-Asset Directories?

That was definitely it. Thank you so much. I must have missed that last little bit at the end of the document.

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