Comparison of names

Discussions about Coding and Scripting
Post Reply
User avatar
Barbie
Godlike
Posts: 1772
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Comparison of names

Post by Barbie » Mon Feb 17, 2020 5:33 am

I stumbled over the case handling of names in UT. If I have two names and want to check if they are equal, I can ignore the case, because there cannot be two names that only differ in case. So, instead of

Code: Select all

string(Name1) ~= string(Name2)
I can simply use

Code: Select all

Name1 == Name2
Correct?

See also: https://wiki.beyondunreal.com/Types#Name
Last edited by Barbie on Mon Feb 17, 2020 7:47 am, edited 1 time in total.
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett

User avatar
sektor2111
Godlike
Posts: 4331
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Comparison of names

Post by sektor2111 » Mon Feb 17, 2020 7:33 am

Barbie wrote:
Mon Feb 17, 2020 5:33 am
Correct?
Me having doubts... An old plain situation - I was hunting CreatureFactory VS Counters (and some known Custom Counters) for adjusting stupid spam. I got a surprise in some map (too bad I don't recall name) which has names like gasbags01 then gabags02 and or other gasbagsend.
I don't know what did I do wrong or I did not do wrong - I always do check for compiling with no errors but the result in game has made me to remove that thing. Of course I could see problem only in a map - I had maps sorted not everything found on Internet for MonsterHunt. Here I suspected an Engine problem or whatever it was and I stopped my names tweaking in that time. Right now I'm hoping to be my mistake but... I'm not convinced that I was doing something wrong...
As a matter of fact: See Editor finding an Actor based on Tag. Type there "Monster", in a MH map, perhaps actors listed immediately are about to be MonsterEvent and MonsterEnd as long as they are including sequence "Monster". If this way of doing deals with names exist in run-time too, then you might have other executions than expected. Now I really want this to be a wrong assumption but the fact which I witnessed is proving another situation...
All patch plugins for NavAdder are using "string(Name)" and for that thing I did not have any problem. Perhaps right now I will want to re-check what's the deal here but I need to look for some map with such common string parts intensively used...

User avatar
Barbie
Godlike
Posts: 1772
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: Comparison of names

Post by Barbie » Mon Feb 17, 2020 8:00 am

"gasbagsend" is used in MH-UM-Capslock. "gasbags01" is not contained in any of my MH maps.
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett

User avatar
sektor2111
Godlike
Posts: 4331
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Comparison of names

Post by sektor2111 » Mon Feb 17, 2020 10:25 am

This is a virtual sample which I've mentioned because I don't recall right now what exactly was there (gasbag, manta, whatever) but... I've stopped doing that type of deal exactly because of this problem and if I well recall it was another one where two counters have been connected with a Factory for two different things - heavy deal to match what event would do certain action. I'm heading for separate private patch files regarding to each evil map instead of testing names using 'Name' instead of "String".

User avatar
Feralidragon
Godlike
Posts: 5164
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: Comparison of names

Post by Feralidragon » Sat Mar 07, 2020 9:10 pm

Names are case-insensitive identifiers, meaning that "unreal" and "Unreal" are considered equal, so yeah, that's always supposed to work.

For example:

Code: Select all

function postBeginPlay()
{
	local name n1, n2;

	n1 = 'unrealpotato';
	n2 = 'UnrealPotato';

	log("n1 == n2 => " $ n1 $ " == " $ n2 $ " => " $ int(n1 == n2));
}
outputs:
n1 == n2 => unrealpotato == unrealpotato => 1

Meaning that when you assign "UnrealPotato" in this case, capitalized, since this name has already been first registered as "unrealpotato" (all lowercase), "unrealpotato" is the assumed name and not "UnrealPotato", so the direct comparison will always yield true.

Post Reply