Using WordList as txt file and using LoadFile

i used the txt file and LoadFile and loaded word to member variable WordList then used RemoveAll() to removed non-isogram function. I also used a random function to select a word from the WordList array to setup the HiddenWord .Here are some partial parts ;

void UBullCowCartridge::BeginPlay() // When the game starts
{
    Super::BeginPlay();
    const FString WordListhPath=FPaths::ProjectContentDir() / TEXT("WordList/WordList.txt");
    FFileHelper::LoadFileToStringArray(WordList, *WordListhPath);
    WordList.RemoveAll([this](auto& word) {return IsIsogram(word); });
    SetupGame();
    PrintLine(TEXT("Hidden Word List has %i"), WordList.Num());  
}

Here 's the SetUpGame()

void UBullCowCartridge::SetupGame()
{
    // welcome message
    PrintLine(TEXT("Welcome to BULLCOW GAME"));

    //HiddenWord = TEXT("unreal");
    HiddenWord = WordList[FMath::RandHelper(WordList.Num())];
    Lives = HiddenWord.Len();
    bGameOver = false;

    PrintLine(TEXT("Guess the %i letter hidden word"), HiddenWord.Len());
    PrintLine(TEXT("You have %i lives"), HiddenWord.Len());
    PrintLine(TEXT("Type your guess \nPress enter to continue..."));
}

Here is also my IsIsogram() function; i used a FString member function FindLastChar();

bool UBullCowCartridge::IsIsogram(const FString& Guess) const
{
    int32 Position{0};
    for(int32 Index=0; Index<Guess.Len(); ++Index) 
    {
        Guess.FindLastChar(Guess[Index], Position);
        if(Position != Index) return true;
    }
     
    return false;
}

Pretty nifty though unless youā€™re IsIsogram does the opposite you are missing a ! in your predicate.

This is actually how I was doing it but didnā€™t like that it was allocating a (possibly) large amount of data just to throw it away so thatā€™s why I added the WithPredicate version of LoadFileToStringArray.
At the time Unreal didnā€™t have a string view class so couldnā€™t really do away with allocating the strings unfortunately :frowning: .

1 Like

yes my IsIsogram is the opposite of the classā€¦
and thanks I did not know LoadFileStringArray has predicate option ā€¦that is cool

and yes to string_view , I tried that earlier for a better functionā€¦maybe we could ask Unreal to add on their GitHub site or maybe try to add our local copy of the engine with some guidance from Unrealā€¦
or we can just call Data() function of FString and write some helper function that almost works as a string_view . it is actually a const char* and and also stores the size / lengthā€¦maybe unreal has a type like that already because game engines were using that type of constructs earlierā€¦:slight_smile:

Then I suggest you rename it to accurately describe what it does.

It does now in 4.25 unsurprisingly called FStringView, but it didnā€™t at the time I made the PR.

I see somehow in my Isogram meaning repeating repeating words :slight_smile: I will revise the true and false statements in the finction and add ! to whereever i have IsIsogram()

Thanks for remindingā€¦ And thanks for 4.25 info i will probably download that version Probably they just implemented similar Member function instead of adding Stl library :+1::+1:

I will revise my code and post later.
I was wondering i should install 4.25 amd rhen delete my 4.22 version Hopefully it wont break anythng here :slight_smile:

i revised the code revised Isogram but i could find predicate version LoadFileToStringArray() . there is only this;
bool FFileHelper::LoadFileToStringArray( TArray<FString>& Result, const TCHAR* Filename, EHashOptions VerifyFlags )

EHashOptions is for async task to verify the hash; (??) but this is not the predicate version

enum class EHashOptions
{
	None                =0,
	/** Enable the async task for verifying the hash for the file being loaded */
	EnableVerify		=1<<0,
	/** A missing hash entry should trigger an error */
	ErrorMissingHash	=1<<1
};

Here is my revised BeginPlay();

void UBullCowCartridge::BeginPlay() // When the game starts
{
    Super::BeginPlay();
    const FString WordListhPath=FPaths::ProjectContentDir() / TEXT("WordList/WordList.txt");
    FFileHelper::LoadFileToStringArray(WordList, *WordListhPath);
    WordList.RemoveAll([this](auto& word) {return !IsIsogram(word); });
    SetupGame();
    PrintLine(TEXT("Hidden Word List has %i"), WordList.Num());  
}

It was added in 4.25

i just saw there is even a section in classā€¦i just installed 4.25 ā€¦will that be ok if i open this project with 4.25 do you thinkā€¦it looks like heavier engine but early to say when first installed i did a sample project with ray tracing enableā€¦it seems working okā€¦ now ā€¦i will test couple of days if it goes ok then i will switchā€¦my desktop wont have problem probablyā€¦although my laptop has rtx2060 with 16gb ram MSI gaming setupā€¦so it should be ok i guessā€¦:slight_smile:

i switched 4.25 ā€¦and i opened the project with 4.25 .at the beginning it gave me some errorsā€¦i rebuild the project within Unreal engine and compiled and tested the function and also revised the BeginPlay() implemented the predicate version;

FFileHelper::LoadFileToStringArrayWithPredicate(WordList, *WordListhPath, [this](const auto& word) {return IsIsogram(word); });

thnk you so muchā€¦saved so much resource. But it was kinda all these error messages due to switching engine revisions when first setting the projectā€¦finally everything works stable so far :slight_smile:
thnk you so much :slight_smile:

void UBullCowCartridge::BeginPlay() // When the game starts
{
    Super::BeginPlay();
    const FString WordListhPath=FPaths::ProjectContentDir() / TEXT("WordList/WordList.txt");
    //FFileHelper::LoadFileToStringArray(WordList, *WordListhPath);
    FFileHelper::LoadFileToStringArrayWithPredicate(WordList, *WordListhPath, [this](const auto& word) {return IsIsogram(word); });
    //WordList.RemoveAll([this](auto& word) {return !IsIsogram(word);});
    SetupGame();
    PrintLine(TEXT("Hidden Word List has %i"), WordList.Num());  
}

hi Dan
Recently i have been experiencing slower compile times when i make a change to code in 4.25.

there was a similar issue with 4.22 which was caused by unnecessary reflection calcs and was resolved by opening UEEditorHeaderTool.target file and making a small space change and savingā€¦

but 4.25 is not giving an error like that.
Normally it compiles under 2 seconds but when i just a comment line //
then the compile time goes to 69 seconds way way to high
here is my output from message log
Using ā€˜git statusā€™ to determine working set for adaptive non-unity build (C:\Developer\unreal_class\BullCowGame-starter-kit).
Building BullCowGameEditorā€¦
Using Visual Studio 2019 14.26.28806 toolchain (C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801) and Windows 10.0.18362.0 SDK (C:\Program Files (x86)\Windows Kits\10).
[Upgrade]
[Upgrade] Using backward-compatible build settings. The latest version of UE4 sets the following values by default, which may require code changes:
[Upgrade] bLegacyPublicIncludePaths = false => Omits subfolders from public include paths to reduce compiler command line length. (Previously: true).
[Upgrade] ShadowVariableWarningLevel = WarningLevel.Error => Treats shadowed variable warnings as errors. (Previously: WarningLevel.Warning).
[Upgrade] PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs => Set in build.cs files to enables IWYU-style PCH model. See https://docs.unrealengine.com/en-US/Programming/BuildTools/UnrealBuildTool/IWYU/index.html. (Previously: PCHUsageMode.UseSharedPCHs).
[Upgrade] Suppress this message by setting ā€˜DefaultBuildSettings = BuildSettingsVersion.V2;ā€™ in BullCowGameEditor.Target.cs, and explicitly overriding settings that differ from the new defaults.
[Upgrade]
Distributing 4 actions to XGE
--------------------Build System Warning---------------------------------------
Temporary license has expired:
Your Agentā€™s temporary license has expired. IncrediBuild will allow you to utilize up to 16 cores on your local machine.
To unleash IncrediBuildā€™s capabilities to utilize idle cores in your network in order to achieve increased performance, please contact sales@incredibuild.com


--------------------Project: Default-------------------------------------------
BullCowCartridge.cpp (1:02.87 at +0:00)
UE4Editor-BullCowGame-0399.lib (0:00.11 at +1:02)
Creating library C:\Developer\unreal_class\BullCowGame-starter-kit\Intermediate\Build\Win64\UE4Editor\Development\BullCowGame\UE4Editor-BullCowGame-0399.lib and object C:\Developer\unreal_class\BullCowGame-starter-kit\Intermediate\Build\Win64\UE4Editor\Development\BullCowGame\UE4Editor-BullCowGame-0399.exp
UE4Editor-BullCowGame-0399.dll (0:00.61 at +1:02)
Creating library C:\Developer\unreal_class\BullCowGame-starter-kit\Intermediate\Build\Win64\UE4Editor\Development\BullCowGame\UE4Editor-BullCowGame-0399.suppressed.lib and object C:\Developer\unreal_class\BullCowGame-starter-kit\Intermediate\Build\Win64\UE4Editor\Development\BullCowGame\UE4Editor-BullCowGame-0399.suppressed.exp
BullCowGameEditor.target (0:00.17 at +1:03)
---------------------- Done ----------------------

Rebuild All: 1 succeeded, 0 failed, 0 skipped

1 build system warning(s):

  • Temporary license has expired

Total time in XGE executor: 63.97 seconds
Total execution time: 64.69 seconds

Privacy & Terms