Checking for partial matches in a string

Hey there, got a bit of an odd one here today.

Is this possible/reasonable. Have a question I'm not exactly sure how to articulate without an example

In a small test game I'm working on I let the player name themselves at the start(and they can change the name at various points but that's isn't part of the problem)and its of course stored in the alias attribute. Everything simple so far.

I'd like to set up a door to only let a person in if they are part of a certain family, now of course I could easily have it check a full name like Joe Smith, but could I make it to check some partial match where it would pass any name that had “Smith” in it for example.

I know I could take the “Easy” way out and have folks enter a first and last name, checking the last, but curious if it is possible to have code check for phrases in a string, it almost sounds like something of the ask/tell function. It could be useful if people say certain trigger phrases during an interrogation.


You could use regular expressions. Check out these links, and see if it helps (or could work). If not, ask more questions. :)

http://docs.textadventures.co.uk/quest/functions/isregexmatch.html
http://docs.textadventures.co.uk/quest/functions/getmatchstrength.html


and there's also the string manipulation functions too:

such as 'StartsWith', 'EndsWith', 'Mid', and 'Instr/InstrRev'

http://docs.textadventures.co.uk/quest/functions/ (scroll down to the very bottom, to the 'String Functions' section)

but Jay's links are the more powerful/useful Functions.


ohh this looks like some fun stuff to read and look into, the whole Regrex thing looked to scary to start with initially but seeing those functions makes it seem at least approachable. I'll get back if i have any questions. I think the "Endswith" will be the most useful for this specific situation
Thank you for your help Jay and HK

Edit- Yes the Endswith worked perfectly, and now I've got new string functions to learn about and use as well, thank you so much


I believe the 'regex/strength' Functions that Jay give do the same thing, but more similiar to a Command's 'pattern' syntax, and with more code symbols and etc that makes it look more scary/foreign to both you and I, laughs.

'StartsWith' is perfect for dealing with Cloned Objects, as when clones are made, just numbers are added to the end of their names:

original Object's 'name' (ID) String Attribute: ball
Cloned Object's 'name' (ID) String Attribute: ball1 // or maybe like this (I've not used cloning yet lol): ball_1

so, via 'StartsWith' Function: if (StartsWith (YOUR_OBJECT, "ball"), will reference your cloned Objects

and if you also use 'LengthOf', you can EX-clude the original Object: if (StartsWith (YOUR_OBJECT, "ball") and LengthOf (YOUR_OBJECT) > "ball")

the 'EndsWith' works well for when you use an organized naming convention/system, such as mine for example:

orc_object
ogre_object
orc_object.dead_boolean_attribute
orc_object.flying_boolean_attribute
orc_object.condition_stringlist_attribute
orc_object.current_life_integer_attribute
orc_object.maximum_life_integer_attribute
orc_object.current_mana_integer_attribute
orc_object.maximum_mana_integer_attribute

if (EndsWith (YOUR_OBJECT, "_object"))
if (EndsWith (YOUR_OBJECT, "_attribute"))
if (EndsWith (YOUR_OBJECT, "_boolean_attribute"))
if (EndsWith (YOUR_OBJECT, "_integer_attribute"))
if (EndsWith (YOUR_OBJECT, "_life_integer_attribute"))
if (EndsWith (YOUR_OBJECT, "_mana_integer_attribute"))


the 'mid' Function is a bit more weird... as I tihnk it starts from the middle and goes out in both directions for looking for your specified string, so it's probably for 'palindromes', for example:

'abccba' or 'abcdcba'
'zyxxyz' or 'zyxwxyz'
(can't think of a palindrome actual word at the moment, lol)


the 'Instr/InstrRev' Functions will look for a specified string in/through the entire String Input, and not just specifically at the start/end/mid. The 'instr' looks through the String Input (aka, it starts) from the left, and the 'InstrRev' (Rev for reverse) looks through the String Input (aka, it starts) from the right)

using it is a bit different, as it returns the position number of where the specified string is found within the String Input, for example, I think this is how it works (haven't used it yet myself):

Instr ("abc", "a") would return '1'
Instr ("abc", "b") would return '2'
Instr ("abc", "c") would return '3'
Instr ("abc", "d") would return '0' // FAILURE to find the specified string in the String Input

InstrRev ("abc", "a") would return '3' // or maybe it's still '1'
InstrRev ("abc", "b") would return '2' // or maybe it's still '2'
InstrRev ("abc", "c") would return '1' // or maybe it's still '3'
InstrRev ("abc", "d") would return '0' // FAILURE to find the specified string in the String Input

if (not Instr ("abc", "b") = 0) -> TRUE/SUCCESS, nested scripting is run
vs
if (not Instr ("abc", "d") = 0) -> FALSE/FAILURE, nested scripting is NOT run / it is skipped over


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums