How Name to String…?

Discussions about Coding and Scripting
Jojonew
Novice
Posts: 22
Joined: Fri Oct 28, 2022 12:46 am
Personal rank: 10

How Name to String…?

Post 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
Deaod
Average
Posts: 43
Joined: Fri Jul 10, 2020 9:22 am

Re: How Name to String…?

Post 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.
Last edited by Deaod on Sun Jul 09, 2023 3:27 pm, edited 1 time in total.
User avatar
sektor2111
Godlike
Posts: 6438
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: How Name to String…?

Post 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.
Jojonew
Novice
Posts: 22
Joined: Fri Oct 28, 2022 12:46 am
Personal rank: 10

Re: How Name to String…?

Post by Jojonew »

:rock: