(solved) [zscript] partial string match?
Moderator: GZDoom Developers
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
- Jekyll Grim Payne
-
- Posts: 1065
- Joined: Mon Jul 21, 2008 4:08 am
- Preferred Pronouns: He/Him
- Graphics Processor: nVidia (Modern GZDoom)
- Contact:
(solved) [zscript] partial string match?
I wonder if it's possible to match two string values partially, i.e. if a string contains "WOOD" in it, ignoring characters before and after?
Last edited by Jekyll Grim Payne on Thu Jan 10, 2019 1:49 am, edited 1 time in total.
Re: [zscript] partial string match?
Sure, when String.IndexOf() returns positive number or zero.
- Jekyll Grim Payne
-
- Posts: 1065
- Joined: Mon Jul 21, 2008 4:08 am
- Preferred Pronouns: He/Him
- Graphics Processor: nVidia (Modern GZDoom)
- Contact:
Re: (solved) [zscript] partial string match?
A question related to this... in the below code, I was wondering why it's necessary to use String.Format() in front of this function, considering that GetClassName() returns a string already:
instead of
Code: Select all
if ( String.Format(GetClassName()).IndexOf("Vile") )
Code: Select all
if ( GetClassName().IndexOf("Vile") )
- phantombeta
- Posts: 2084
- Joined: Thu May 02, 2013 1:27 am
- Operating System Version (Optional): Windows 10
- Graphics Processor: nVidia with Vulkan support
- Location: Brazil
Re: (solved) [zscript] partial string match?
Because the wiki is wrong, actually. GetClassName returns a name, not a string, and names are ints generated from a string with a hashing algorithm (so that different strings get different numbers).
That said, using String.Format like that is janky IMO. It's abusing the fact that the compiler will implicitly cast names to strings. Which is fine, since apparently there's no explicit casting, but there's a much simpler, better and less performance-wasting way to do it:
That said, using String.Format like that is janky IMO. It's abusing the fact that the compiler will implicitly cast names to strings. Which is fine, since apparently there's no explicit casting, but there's a much simpler, better and less performance-wasting way to do it:
Code: Select all
string className = GetClassName ();
if (className.IndexOf ("Vile"))
Re: (solved) [zscript] partial string match?
Ok, that's good to know, thanks. Actually, I'm aware of using a separate string variable like you showed, I just considered the code I wrote to be more compact. Didn't know it wastes performance, though.