${pcname} ends with 's or '

Hello I’m having trouble with figuring out how to code grammar to correctly fit pc’s name.

If pc’s name ends with an s, referring to something of theirs would end with an apostrophe.
E.g:
Silas’ shoes
Camilla’s shirt

How do you make it so the code knows if the name ends with an ‘s’ or not? Is this possible?

Or would it be easier to just make a choice for the player to choose which fits their name? (The thing is I don’t want to implement the option if it’s avoidable, as it’s an annoying question to ask)

It’s technically not incorrect to use 's for names ending with an s. It’s more of a convention. You could use cslib to split the string to see if it ends in an ‘s’ , but I don’t think it’s worth the hassle.

5 Likes

ah okay, didn’t actually know this so thanks! I found a way around it I think :))

1 Like

Like @quartz said, it’s grammatically okay to write Silas's. But if you really want to go there, you can do something like this:

*temp endsWithS (pcname#(length(pcname)) = "s")

I’m writing it from the top of my head, so it might not be 100% correct.

2 Likes

Thanks!

This will not work, I think.

It should be:

*temp edited_name ""
*temp i 1

*if (pcname#(length(pcname)) = "s")
    *set edited_name (pcname&"’")
    *goto continue
*else
    *set edited_name (pcname&"’s")
    *goto continue

*label continue
The players shoes are: $!{edited_name} shoes, because they belong to ${pcname}!

Bruh.

2 Likes

well damn, I guess I gotta up my code game, cause I understand nada of this. But ey thanks a lot anyway

1 Like

If I remember correctly, the style guide for CoG authors actually mandates the usage of 's for names ending in s, possibly for this reason.

2 Likes

Okay I explain:

First I created a variable named “edited_name” where we will write the player name with a possesive sufix, that, we still don’t know if is a “'” or a “'s”…

*temp edited_name ""

Then we check if the last letter of pcname variable is a “s”.

You can check the last char of any variable by adding “#length(name_of_variable)” beside the variable.

Like this:

Last_letter = name_of_variable#(length(name_of_variable))

Will always return the last letter of the variable.

So let’s compare the (last_letter) to “s”.

*if (pcname#(length(pcname)) = "s")
    *set edited_name (pcname&"’")
    *goto continue
*else
    *set edited_name (pcname&"’s")
    *goto continue

Saw what I did?
If the last letter is “s”, then the edited name will receive the ${pcname} and “'s” chars!

Now let’s print the result:

*label continue
The players shoes are: $!{edited_name} shoes, because they belong to ${pcname}!

Easy peasy… :smiley:

2 Likes

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.

3 Likes

@Nahim_Kerman Thanks for the explanation!

@will Thank you for simplifying it for me, and explaining it further. I understand the code now and will use it in my game :))

I now know its not incorrect to write ‘s if the name ends with s, but it just looks wrong to me, especially since I usually play with a name that ends with two s’ and it ends up being three in a row. So I’m grateful for the solution.

3 Likes

It will work for what it was supposed to :joy:. It’s just a boolean, how the author will use is a different matter.

1 Like

Wow, really? I thought choicescript didn’t accepted operators like equals (“=”) while declaring a new variable?

1 Like

It does if you surround them in paranthesis.

2 Likes