Page 1 of 2

User input names, making character names not bold [RESOLVED]

Posted: Sat Sep 24, 2011 11:59 pm
by Variasaber
Hi guys. I registered here just now because there's something I need to ask about. Some other folks and I are working with Ren'Py for a project, and we've just recently started coding our game after going through the tutorials. Almost immediately we hit our first roadblock.

We're trying to set it up so that the game starts out by asking you what you want your character's name to be. We have it set up to receive text input from the player and store that as a variable, and then define a character whose name is set to that variable.

Here's the code for the user input:

Code: Select all

$ pov = renpy.input("Enter your name, or press Enter to continue.") or "John D."
And here's the code for the Character definition:

Code: Select all

define h = Character(pov, color="#58D3F7")
This returns an error. We then tried adding this a few lines before the user input code:

Code: Select all

define pov= 'John D.'
And that all checks out, but the Character's name then always comes out as John D. regardless of the user input.
The best I can figure is that Ren'Py is recognizing "define pov" and "$ pov" as different variables since one is a Python script and the other isn't, but the Character definition returns an error if you try to put a Python script in it (putting a $ before pov).

Does anyone know how to use user input to set a Character name?


Also, when displaying dialogue, Character names are shown in bold. This would be fine except that it makes the font we're using hard to read unless it's set unreasonably large. Does anyone know how to make the Character names display without bold?

Any help is greatly appreciated :mrgreen:

Re: Setting Character names from user input, and something e

Posted: Sun Sep 25, 2011 2:21 am
by Soraminako
I had a similar problem in the past, and found out how to do it from someone's kind help in another thread.
I don't remember which thread but here's the code:

Code: Select all

# The phrase in the brackets is the text that the game will display to prompt 
# the player to enter the name they've chosen.

    $ player_name = renpy.input("What is your name?")

    $ player_name = player_name.strip()
# The .strip() instruction removes any extra spaces the player may have typed by accident.

#  If the player can't be bothered to choose a name, then we
#  choose a suitable one for them:
    if player_name == "":
        $ player_name="John D."
 
# Now the other characters in the game can greet the player.
  
    e "Pleased to meet you, %(player_name)s!"
    #Edit: If you are using the new version of ren'py, use the following line instead of the one above, since that changed:
    #e "Pleased to meet you, [player_name]!"
And you define the character like this:

Code: Select all

    $ p = DynamicCharacter("player_name", color="#58D3F7")

Re: Setting Character names from user input, and something e

Posted: Sun Sep 25, 2011 12:31 pm
by manga_otaku
Instead of

Code: Select all

$ pov = renpy.input("Enter your name, or press Enter to continue.") or "John D."
try

Code: Select all

$ pov = renpy.input("Enter your name, or press Enter to continue.", "John D.")
When defining a character as a user inputs name, you put it in speech marks as well. For instance:

Code: Select all

define h = Character("pov", color="#58D3F7")
Well that's what I think anyway xD

Re: Setting Character names from user input, and something e

Posted: Sun Sep 25, 2011 7:04 pm
by Variasaber
Thanks for the help, guys :mrgreen: I actually ended up finding how to make it work, a friend of mine showed me. My mistake was trying to put the $ next to pov in the Character definition; it's supposed to go at the beginning of the line. After doing that, everything works great. :mrgreen:

But, Soraminako, thanks a bunch for the player_name.strip() and %(player_name)s functions! (Is that S after the close-paren necessary for that to work, or would that just make an S appear after the player's name?)

The issue remains, though, of the bold names. I sure hope that's fixable, probably in options.rpy or something...

Re: Making character names not bold (User input names resolv

Posted: Sun Sep 25, 2011 7:15 pm
by Aleema

Code: Select all

style.say_label.bold = False
There you go.

Re: Making character names not bold (User input names resolv

Posted: Sun Sep 25, 2011 10:07 pm
by Variasaber
Aleema wrote:

Code: Select all

style.say_label.bold = False
There you go.
Excellent! Thanks very much!

Since that's a style modifier, I suppose it belongs in options.rpy, but I'm guessing such settings can also be put in script.rpy if the setting were to change partway through the game.

I'll have to do some more exploring before I ask anything else; I don't want to waste anyone's time with things I could have easily discovered on my own. But once again, thanks a ton for everything, you guys! :mrgreen:

Re: Setting Character names from user input, and something e

Posted: Mon Sep 26, 2011 11:57 pm
by Soraminako
Variasaber wrote:[...]Soraminako, thanks a bunch for the player_name.strip() and %(player_name)s functions! (Is that S after the close-paren necessary for that to work, or would that just make an S appear after the player's name?)
The "s" is necessary. I wondered the same thing at first too. XD Code is weird like that...

Re: User input names, making character names not bold [RESOL

Posted: Tue Sep 27, 2011 6:51 am
by Aleema
If you're wondering why, there's an FAQ entry on it. The S stands for "string".

Re: Setting Character names from user input, and something e

Posted: Wed Oct 05, 2011 12:04 pm
by HikariYamino
Variasaber wrote:Thanks for the help, guys :mrgreen: I actually ended up finding how to make it work, a friend of mine showed me. My mistake was trying to put the $ next to pov in the Character definition; it's supposed to go at the beginning of the line. After doing that, everything works great. :mrgreen:

But, Soraminako, thanks a bunch for the player_name.strip() and %(player_name)s functions! (Is that S after the close-paren necessary for that to work, or would that just make an S appear after the player's name?)

The issue remains, though, of the bold names. I sure hope that's fixable, probably in options.rpy or something...
Wait!!! Uhh, i still can't do it... Can you copy and paste the correct code here that you used?? There seems to be an error in everything i did OTL

Re: User input names, making character names not bold [RESOL

Posted: Sat Nov 12, 2011 8:11 pm
by kiriyamiko
Hi. I'm new to all this, and I know this was resolved but i followed the code exactly (I think. If there's something I'm doing wrong please tell me.)

Code: Select all

$ player_name = renpy.input("I dunno. What is it then?")
$ player_name = player_name.strip()
if player_name == "":
    $ player_name="Shou"
and i put the defining like this

Code: Select all

define p = DynamicCharacter("player_name", color="#c8ffc8")
however, when i test out my visual novel and use %(player_name)s , instead of the name i inputted, It's say "Nice to meet you %(player_name)s".
No name just the code.
I've been driving myself crazy, does anyone have an idea of what I've done wrong/ should be doing?

Re: User input names, making character names not bold [RESOL

Posted: Sat Nov 12, 2011 8:22 pm
by Aleema
Do you have the newest Ren'Py? If so, the variable format has changed. Now you just put [brackets] around it. The FAQ entry should be updated to explain more.

Re: User input names, making character names not bold [RESOL

Posted: Sat Nov 12, 2011 10:04 pm
by kiriyamiko
Aleema wrote:Do you have the newest Ren'Py? If so, the variable format has changed. Now you just put [brackets] around it. The FAQ entry should be updated to explain more.
You are a life saver and I love you :|
Thank youuuuuuuuu <3

Re: User input names, making character names not bold [RESOL

Posted: Fri Dec 23, 2011 4:56 pm
by ebi brain
Sorry to bump an older thread, but I'm having the same problem as kiriyamiko...
and I don't really understand what I have to put brackets around:/

if someone could show an example, I'd be really grateful...

Re: User input names, making character names not bold [RESOL

Posted: Fri Dec 23, 2011 8:00 pm
by manga_otaku
Instead of the old %(player_name)s to show the players inputted name, you now use square brackets.
To show the chosen name when using the character pov, you would put:

Code: Select all

"My name is [player_name]"

Re: User input names, making character names not bold [RESOL

Posted: Sat Dec 24, 2011 10:36 am
by ebi brain
Aaaah now I get what I did wrong, I kept the % and s.
Thanks so much.