Simplest way to do it:
*create ends_with_s false
...
*if (name#(length(name)) = "s")
*set ends_with_s true
...
$!{name}@{ends_with_s '|'s}
Create a variable called ends_with_s. When the player’s name is determined, check if their name ends with an S.
Let’s say the name is Sam. We want to check if the last letter of the name is S, so we need to check the third letter. To do so, we use this bit of code: name#3
. That’ll get you third letter: M.
However, if the name is Lassie, using name#3
means we’ll still check the third letter and get S, even though what we want is to get the sixth letter, E. So how do we always get the right length?
length(name)
gets us the number of characters in the string name
. So, if name is Sam, we get 3, and if it’s Lassie, we get 6.
Therefore, we can check the last letter of a name with name#(length(name))
.
Then we just turn that into an if statement, as above, which turns ends_with_s
true if the name ends with S.
And then, whenever we need a possessive throughout the entire game:
$!{name}@{ends_with_s '|'s}
The code ${name}
prints the string name
and adding an exlamation mark ($!
) capitalises the first letter.
The code @{ends_with_s
checks the variable ends_with_s and sees it’s a boolean, and then prints one of two options, depending on if it’s true or false (starting with true). Separate the two options with a solid line |
. If the name ends with S, we want it to just do an apostrophe, and if it doesn’t, we want an apostrophe and an S. So, @{ends_with_s '|'s}
.
And there you have it! That code will print both Sam's
and Carlos'
.
That said, the others are right: Carlos’s is fine. If you think it’s worth the effort, though, go for it, and it’s a good test of some basic string manipulation and multireplace commands.