Checking the last few letters of an input

Hey, quick question:

How do I check again if the last couple of letters in a player input fit into a certain pattern?

As in if the player enters a word ending in -tite that a certain flavortext/variable is triggered?

Is that eve possible or am I mixing up functions?

I’ve not used it myself but from the advanced ChoiceScript page, there’s this:

Characters: You can extract the characters (letters/numerals) out of a variable, like this:

*temp word "xyzzy"
*temp first_letter word#1
*temp second_letter word#2
The first letter of the word "${word}" is ${first_letter} and the second letter of the word is ${second_letter}.
1 Like

That’s the base I’m working off. I vividly remember someone once posting a template for checking the last few letters of an input, but I cannot locate that again ;_;

Use the length function to find the index for the last letter, and work backwards from there.

I fumbled about a bit to find the wiki article I needed, but here it is: Extracting letters/numerals from variables.

3 Likes

CSLib has a subroutine called substring that allows extracting parts of strings. It works like this:

*gosub_scene cslib_string substring <string> <starting point (number)> <end point (number)>

For example:

*gosub_scene cslib_string substring "Hello, World!" 1 5

Thw above would yield a string starting with the first character and ending with the fifth, Hello.

In your use case, it would look something like this:

*gosub_scene cslib_string substring my_variable (length(my_variable) - 2) lenght(my_variable) 

The above would yield the last 3 characters of the string. Note that I subtracted 2 instead of 3, because the starting and ending points are inclusive.


3 Likes