• To improve security, we will soon start forcing password resets for any account that uses a weak password on the next login. If you have a weak password or a defunct email, please update it now to prevent future disruption.

Tutorial Ren'Py Naming characters

P_S_Y_C_H_O

therappist
Game Developer
Sep 3, 2018
756
3,090
How to put default name into input line when you let player decide how to name a character?
All I can find is empty space and if left empty the name will remain default.
$ m = renpy.input("Hi! My name is... ")
$ m = m.strip()
if m == "":
$ m="defaultname"

But it's not good enough.
I want player to see what name did I give to a character before they decide to change it.
Is it even possible? Thanks
 
Oct 30, 2018
395
1,143
So the renpy.input() method can be overridden to take 6 arguments, but the first 2 are the important ones for this problem- your prompt argument and your default. The prompt is the what you're asking the player to input and the default is what's going to be on the input line by when the user first sees it (it's the thing they edit)

In your case the prompt is the string "Hi! My name is.." and you want the default to be your characters default name variable

So the code would look something vaguely like renpy.input("Hi! My name is...", defaultname)
 
  • Like
Reactions: P_S_Y_C_H_O

P_S_Y_C_H_O

therappist
Game Developer
Sep 3, 2018
756
3,090
Unfortunately I'm getting error that my 'defaultname' is not defined.
I used only first letter to define a character. Should I define him with full 'defaultname' which I will use there in the input?
It will be pain to write it thousands times later on...
TRying to define full name giving more errors but maybe just because later on in script I already used first letter in dialogue.
Should it be like this?
define m = Character("Mike", who_color="#12fdea")
$ m = renpy.input("Hi! My name is...", Mike)

$ m = m.strip()

if m == "":
$ m="Mike"
 
Oct 30, 2018
395
1,143
So my example was if under the context of you having a dedicated variable to your MCs default name, I'm sorry if I didn't make that clear. If you don't that's fine you can always write a string in the default field anyway. i.e renpy.input(prompt, default= "").

Yes I think that solution you've given should work.
 
  • Like
Reactions: P_S_Y_C_H_O

P_S_Y_C_H_O

therappist
Game Developer
Sep 3, 2018
756
3,090
Thanks mate.
It should be like this
$ m = renpy.input("Hi! My name is...", default='Mike')

And it even works without defining 'Mike'. Cool
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,202
14,944
People tend to see the function of Ren'py as something way more simple than it really is. There's a lot of useful parameters to help you have a full control of what will be entered by the player.
The best use of it is probably this one :
Code:
define mc = Character( "" )

label blabla:
    [...]
    $ mc.name = renpy.input( "Enter your name", 
        default="defaultName",
        allow="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopwrstuvwxyz-'",
        length=10 ).strip().title()
It do everything in a single line, and also limit the wildness of the player.
Limiting the authorized characters can be really useful, especially if you use a font that isn't the one by default and can have a limited range of covered characters. Anyway it will look better if your game is in English only, since the name will be wrote in Latin alphabet, according to the rest of the text.
As for the length limit, it ensure that the name will not break your design, nor lead the dialog to overflow from its box.
 

P_S_Y_C_H_O

therappist
Game Developer
Sep 3, 2018
756
3,090
Code:
define mc = Character( "" )

label blabla:
    [...]
    $ mc.name = renpy.input( "Enter your name",
        default="defaultName",
        allow="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopwrstuvwxyz-'",
        length=10 ).strip().title()
will it work if I won't include this line?
Code:
allow="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopwrstuvwxyz-'",
or just add
length=10 ).
edit. Figured it out.
It can be like this
Code:
label blabla:
    [...]
    $ mc.name = renpy.input("Enter your name", default="defaultName",  length=10)
But what is .strip().title() for?
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,202
14,944
will it work if I won't include this line? [...] or just add [...]
Yes, all parameters are optional. I used those to show that there's more than just the question and default value. It also gave me the possibility to explain why they can be useful, but they aren't mandatory. You can use one, all, none, it's all up to you.
 
  • Like
Reactions: P_S_Y_C_H_O