[Solved] About choosing names and caps/case sensitive

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
Adabelitoo
Regular
Posts: 86
Joined: Sat Apr 13, 2019 2:32 pm
Contact:

[Solved] About choosing names and caps/case sensitive

#1 Post by Adabelitoo »

Let's imagine that the player wants to name his character Markus, so I'll do this

Code: Select all

$ mc = renpy.input(What will be your name (Default name will be MC))
$ mc = mc.strip()
Now, let's imagine that the player writes markus or mARKUS instead of Markus. Is it possible to force the name to be Markus?

Also, as another example, let's say that there is a character named Clementine and the player has to manually write (not define, only write) her name, so I'll do this

Code: Select all

if name == Clementine
    #Right answer
else
    #Wrong answer
Now let's imagine again that the player writes clementine or CLEMENTINE or cleMENTine or CLEMENtine (I'm making it absurd to make it clear). Is it possible to make the game recognize that the word introduced is still Clementine? I found about flags like and !cl would do what I need but I don't want to write [mc!cl] every time, I want to force the name to be stored in the rigth way. Thanks for reading.
Last edited by Adabelitoo on Fri Mar 01, 2024 8:04 pm, edited 1 time in total.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2406
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: About choosing names and caps/case sensitive

#2 Post by Ocelot »

Code: Select all

$ mc = mc.capitalize()
< < insert Rick Cook quote here > >

jeffster
Veteran
Posts: 409
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: About choosing names and caps/case sensitive

#3 Post by jeffster »

Use Python string methods:

capitalize() for "This"

Code: Select all

$ mc = renpy.input("What will be your name (Default name will be MC)", default="MC").strip()
$ mcc = mc.capitalize()
if mc != mcc:
    menu:
        "Do you mean [mcc]?"
        "Yes":
            $ mc = mcc
        "No, I mean [mc]!"
            pass
https://docs.python.org/3.8/library/std ... capitalize

And casefold() (RenPy 8+) or lower() (RenPy 7) for conversion to lowercase:

Code: Select all

if name.lower() == "Clementine".lower():
    #Right answer
else:
    #Wrong answer
https://docs.python.org/3.8/library/std ... r.casefold

downover
Regular
Posts: 38
Joined: Sun Feb 25, 2024 1:36 am
Contact:

Re: About choosing names and caps/case sensitive

#4 Post by downover »

> Now let's imagine again that the player writes clementine or CLEMENTINE or cleMENTine or CLEMENtine (I'm making it absurd to make it clear). Is it possible to make the game recognize that the word introduced is still Clementine? I found about flags like and !cl would do what I need but I don't want to write [mc!cl] every time, I want to force the name to be stored in the rigth way.

If you're trying to make the game behave differently when the user's name is set to some form of Clemintine, I would instead save that as a separate bool when the name is created. Something like...

Code: Select all

$ mc_name = renpy.input("What will your name be?").strip()
$ clementine_mode = mc_name.lower() == "clementine"
Then you just need to check for the bool clementine_mode.

User avatar
Adabelitoo
Regular
Posts: 86
Joined: Sat Apr 13, 2019 2:32 pm
Contact:

Re: About choosing names and caps/case sensitive

#5 Post by Adabelitoo »

Thank you everyone for your answers. Everything works as planned now.

Marked as solved.

jeffster
Veteran
Posts: 409
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: [Solved] About choosing names and caps/case sensitive

#6 Post by jeffster »

...Just note that "MC".capitalize() becomes "Mc", not "MC". :-)
That's why an automatic transformation, without user's confirmation, might not be the best for every case (e.g. "MacGuyver" etc.)...

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Ocelot