Using FString as a macro parameter

Hi! I’m trying to use LOCTABLE_FROMFILE_GAME() macro at runtime, so I can load different files accordingly.
The code I currently have is as follows:

273303-code.png

As of right now I’m so confused. I feel like I’ve tried so many things but none of them worked (It doesn’t compile).

Can anyone please give me a hint of what to do make this compile?

Hi Cassio, sorry for the delayed response. I think you need to feed your strings through the TEXT macro:

LOCTABLE_FROMFILE_GAME( TEXT(“Game”), TEXT(“Game”), [VARIABLE HERE );

This is because FStrings are initialised with TCHAR pointers/arrays.

If this doesn’t work, what errors are you getting in Visual Studio?

Hi! Thanks a lot for answering!
I managed to work around it already. I don’t know if its optimized but it is working :slight_smile:
What I did is:
I opened the StringTableRegistry.h to see how the macro is defined. It is defined to this:

/** Creates and registers a new string table instance, loading strings from the given file (the path is relative to the game content directory). */
#define LOCTABLE_FROMFILE_GAME(ID, NAMESPACE, FILEPATH) \
FStringTableRegistry::Get().Internal_LocTableFromFile(TEXT(ID), TEXT(NAMESPACE), TEXT(FILEPATH), FPaths::ProjectContentDir())

(It already has the TEXT() within its definition).
So instead of using the macro, I used the FStringTableRegistry::Get().Internal_LocTableFromFile() function. Instead of the TEXT() macro, I used the TCHAR_TO_UTF8() macro. Like this:

TCHAR_TO_UTF8(File.GetCharArray().GetData())

So the end result is:

FStringTableRegistry::Get().Internal_LocTableFromFile(TEXT("Game"), TEXT("Game"), TCHAR_TO_UTF8(File.GetCharArray().GetData()), FPaths::ProjectContentDir())

And it worked :slight_smile:

Thanks a lot for answering to help me. I’m still getting the hang with UE4’s macros, variables, functions…
I’m answering my own post detailed like this just in case someone in the future face the same problem and can’t find a working solution (like I was). This may help.

Thanks for posting your solution.
It’s also very helpful to mark the question as answered so people can more easily find it.

P.S. - The TEXT macro is specifically for properly interpreting string literals in the code. It essentially tells UE4 how to interpret string literals as an FString. If you look at the Internal_LocTableFromFile footprint, it wants you to pass it an FString. (FStringTableRegistry::Internal_LocTableFromFile | Unreal Engine Documentation). You don’t need TCHAR_TO_UTF8 at all, just call the function and pass it your FString variable.
The original mistake, ironically, was using the LOCTABLE_FROMFILE_GAME macro in the first place, the macro is only there to help you get FStrings (and FNames) from string literals.

P.P.S. - You can pass an FString to a function expecting an FName by dereferencing the FString pointer.

void WantsFName(FName FooName) {}


FString FooString;


void GivesString() {
  WantsFName(*FooString);// this will work

  WantsFName(FooString);// this will not

}