Page 1 of 1

How Name to String…?

Posted: Sat Jul 08, 2023 3:19 pm
by Jojonew
Hello UT friends:

A native project, but I am not familiar with C艹(C++) code .

I want to change a name variable to String, is it possible to create a function in uscript?

Tks
Ag Blue

Re: How Name to String…?

Posted: Sat Jul 08, 2023 4:07 pm
by Deaod

Code: Select all

FName SomeName(TEXT("NameContent"));
const TCHAR* s = *SomeName;
// s now contains "NameContent"
You really should learn C++ if you want to toy with it and also get an IDE like Visual Studio.

Edit: wrapped string literal with TEXT macro.

Re: How Name to String…?

Posted: Sun Jul 09, 2023 5:59 am
by sektor2111
Jojonew wrote: Sat Jul 08, 2023 3:19 pm I want to change a name variable to String, is it possible to create a function in uscript?
Name to String is simple, more complex is String to Name.

Task StringToName
#1 XC_Engine has this capability.
#2 I wrote such function in UScript inside MapGarbage builder - viewtopic.php?p=142521#p142521

Code: Select all

class MapGarbage expands BrushBuilder;
...
var string tmp, AText;
var name NullName;
...
...
final function name StrToName(string AString)
{
	local Name TempName;

	tmp = AString;
	SetPropertyText("NullName",GetPropertyText("tmp"));
	TempName = NullName;
	NullName = '';
	tmp = "";
	return TempName;
}
I do not need C++ for such a simple task - EPIC already have samples in Teleporter.uc about probing matches.

Task NameToString
Reversal Name to String doesn't need mainly anything - also no C++ is required - this is how Teleporters are linked by builder helping editing.

Code: Select all

...
...
SourceTel.URL = string(TheTeleporter.Tag); //Assign the URL String as the Text format for Tagged Destination.
...
...
Doing these because Tag of Destination is a "Name" type, and URL is a "String" type, but they have similar TEXT as data.
And then ? And then you can simply assign String variable from a Name without any function. Core.Object has already this capability.
Another STOCK example is placed in Actor - here were used functions...

Code: Select all

function String GetHumanName()
{
	return GetItemName(string(class));
}
because

Code: Select all

function String GetItemName( string FullName )
{
	local int pos;

	pos = InStr(FullName, ".");
	While ( pos != -1 )
	{
		FullName = Right(FullName, Len(FullName) - pos - 1);
		pos = InStr(FullName, ".");
	}

	return FullName;
}
This is how it was originally dodged as NameToString.

Re: How Name to String…?

Posted: Mon Jul 10, 2023 7:17 am
by Jojonew
:rock: