(solved) [zscript] partial string match?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

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!)
Post Reply
User avatar
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?

Post by Jekyll Grim Payne »

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.
_mental_
 
 
Posts: 3812
Joined: Sun Aug 07, 2011 4:32 am

Re: [zscript] partial string match?

Post by _mental_ »

Sure, when String.IndexOf() returns positive number or zero.
User avatar
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?

Post by Jekyll Grim Payne »

Thanks!
D2JK
Posts: 543
Joined: Sat Aug 30, 2014 8:21 am

Re: (solved) [zscript] partial string match?

Post by D2JK »

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:

Code: Select all

if ( String.Format(GetClassName()).IndexOf("Vile") )
instead of

Code: Select all

if ( GetClassName().IndexOf("Vile") )
User avatar
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?

Post by phantombeta »

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:

Code: Select all

            string className = GetClassName ();
            if (className.IndexOf ("Vile")) 
D2JK
Posts: 543
Joined: Sat Aug 30, 2014 8:21 am

Re: (solved) [zscript] partial string match?

Post by D2JK »

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.
Post Reply

Return to “Scripting”