Undeclared identifier when using a variable name at the beginning of the TEXT macro ?

Hi,

When starting the TEXT macro with some variable name, like this:

GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Green, TEXT(ThisFdP->YagPotential[i].PType) );

I get an “undeclared identifier LThisFdP” error.

Whatever the variable name, it adds a capital L in front of it and gives the error.

The workaround is easy:

GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Green, TEXT(""+ThisFdP->YagPotential[i].PType) );

This occurs only if the variable name is the first word of the argument.

Is that only me ? OR maybe i am misusing the macro ? It seems weird.

Thanks

Hi ,

What is the variable type returned by ThisFdP->YagPotential[i].PType?

Hi ,

PType is a FString:

USTRUCT()
struct FYagPotentialStruct
{
	GENERATED_USTRUCT_BODY()

	UPROPERTY()
		FString PType;
	UPROPERTY()
		FString PName;
	UPROPERTY()
		FString PValue;
	UPROPERTY()
		FString PBonus;

	inline bool operator < (const FYagPotentialStruct &o) const
	{
		return PType < o.PType;
	}

	FYagPotentialStruct()
	{
		PType = "NULL";
		PName = "NULL";
		PValue = "NULL";
		PBonus = "NULL";
	}
};

Hi ,

Instead of using

GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Green, TEXT(ThisFdP->YagPotential[i].PType) );

try this:

GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Green, FString::Printf(*(ThisFdP->YagPotential[i].PType)));

The TEXT() macro is looking for a string of TChar literals, and only a string of TChar literals, which you are not getting when you pass in the variable directly. Printf is also looking for a TChar string, but it has a little more flexibility in terms of formatting and will allow you to dereference a variable to obtain the data the variable contains.

I performed a simple test on the second option, and I believe it should meet your needs. You may even be able to remove the inner-most parentheses, but I did not go that deep in my test. Please let me know if you run into any problems with this and I can run some more thorough tests.

This is perfect. Thanks a lot for the explanations and the help.