Page 1 of 1
Code for defining custom character name not working
Posted: Sat Sep 27, 2014 1:53 pm
by ljnicolson
So I've tried doing this several ways and checked a bunch of other threats on this problem, but I can't find anyone having the same problem as me. I'm trying to define a the main character so their name will appear, but I want the player to be able to choose their name, and the code just doesn't seem to want to work.
When I try this code:
Code: Select all
$ aa = DynamicCharacter("player_name", color="#58D3F7", show_two_window=True)
I get an error message that says
File "game/script.rpy", line 8: Line is indented, but the preceding image statement statement does not expect a block. Please check this line's indentation.
$ aa = DynamicCharacter("player_name", color="#58D3F7", show_two_window=True)
And when I use this code:
Code: Select all
define aa = DynamicCharacter("player_name", color="#58D3F7", show_two_window=True)
This is the error message I get
File "game/script.rpy", line 44, in script
p "Pleased to meet you, [player name]!"
KeyError: u'player name'
This is what my script looks like so far
Code: Select all
# the story starts here
label start:
# 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="Avis"
# Now the other characters in the game can greet the player.
e "Pleased to meet you, [player_name]!"
Any help would be much appreciated!
Re: Code for defining custom character name not working
Posted: Sat Sep 27, 2014 6:27 pm
by Kate
That is a really complicated way of doing that
You just want the player to be able to input a name, right? That's fairly simple, I've been using this:
Code: Select all
k "Welcome!"
k "Prepare to enter the game!"
k "First, I need your name. That way, I know what to call you!"
$ p = renpy.input ("My name is", "", length=20,)
if p == "":
$ p = "Alex"
# [p] is how you address the character in a sentence.
# p is the character's voice.
k "Very good, [p]!"
And I've defined p as this above where you declare images and characters:
Code: Select all
define p = Character('[p]', color="#c8ffc8")
I hope this helps. Anytime you want to address the character, you use [p] and it will input their name. For the character's speaking dialogue, just use p "blah blah" for renpy.
Re: Code for defining custom character name not working
Posted: Sat Sep 27, 2014 10:47 pm
by ljnicolson
Thank you so much!
Okay, so I tried that, and this time it actually loaded the game, but it's still causing problems.
One is that if I input a name, it resets to the title screen without going to the next part of the script. If I click through and it uses the default name, no trouble.
The other is a stylistic thing, and when I click through with the default name, when the character speaks (defined as [p]) the show_two_window=True code doesn't work and their name shows up in the one box. Do you know of a work around for that or should I just set them all to not be in two windows?
Re: Code for defining custom character name not working
Posted: Sun Sep 28, 2014 1:51 am
by 78909087
Hello there, I've actually got a strange way (that works for me, the way I want it to) if you would like to try that?
First: Define the character before the game.
define me = DynamicCharacter("povname", color=(192, 64, 64, 255))
(You can change the colour, and set 'me' to whatever you would like to use to 'call' the character for speech purposes.)
Second: To get the user to then choose their name, use this line
$ povname = renpy.input("What is your name?") or "Eveline"
^ saying 'or "Eveline"' will automatically set the name to Eveline if they hit Enter without entering a name.
Then, to call the character in text, use:
%(povname)s
EG.
gm "Now, now, I know my son is a little hard to live with, but he loves you, %(povname)s..."
will be
gm "Now, now, I know my son is a little hard to live with, but he loves you, Eveline..."
(Or whatever the person entered as their name.)
Re: Code for defining custom character name not working
Posted: Sun Sep 28, 2014 9:15 am
by ljnicolson
And that one worked! Thank you so much!
Re: Code for defining custom character name not working
Posted: Mon Sep 29, 2014 7:42 am
by 78909087
You're welcome

I'm glad I could be of assistance.
Re: Code for defining custom character name not working
Posted: Tue Sep 30, 2014 3:42 pm
by Akuni
Can I put a bump on this thread? I didn't want to start a new topic:
Basically, I've been trying to change the colour of one of my Characters. I've tried both codes, but it still always comes out as white?
Edit: Should've included the actual line of code.
But when I make them normal characters the colour changes apply. I'm not sure if I'm doing something wrong or :c
Re: Code for defining custom character name not working
Posted: Tue Sep 30, 2014 8:56 pm
by yuucie
Akuni wrote:Can I put a bump on this thread? I didn't want to start a new topic:
Basically, I've been trying to change the colour of one of my Characters. I've tried both codes, but it still always comes out as white?
Edit: Should've included the actual line of code.
But when I make them normal characters the colour changes apply. I'm not sure if I'm doing something wrong or :c
You should put your code in [ code ] [ /code ], since it's hard to see.
You're defining the wrong thing. In your definition, you defined your character names as 'Tet'. Your flag for his name then should be
but you wrote
which means you created a new variable over-riding your character's variable.
Re: Code for defining custom character name not working
Posted: Wed Oct 01, 2014 10:50 am
by Akuni
Code: Select all
define Tet = DynamicCharacter('Tet', color="#0B610B")
define Lu = Character('Lu', color="#0B610B")
label start:
"It's already our one year anniversary..."
"And I have no idea what I'm going to do."
$ Tet = "Tet"
Tet "Darn, why didn't I check my calendar earlier?"
Tet "If she finds out I almost forgot about our plans she'll never let me forget it."
Tet "Or worse, she'll be disappointed..."
Tet "Oh wait, what am I doing? I should just use the Internet."
Tet "There's so much on this site..."
Tet "What could I do to make our anniversary special?"
Tet "I better pick something easy."
I tried changing it like you said but the character's name colour still appears white :c Could there be another problem? Or way for solving this? Hopefully its easier to see where I'm going wrong now >.<
Re: Code for defining custom character name not working
Posted: Wed Oct 01, 2014 2:33 pm
by yuucie
It's still over-riding your code. There's two kinds of variables here, the "Tet" variable that defines his in-game name, and the "Tet" variable that you use for dialogue. Previously you had "T" variable for dialogue and "Tet" variable for his in-game name, but now you changed them both to be the same and renpy is confused.
Try this instead:
Code: Select all
define Tet = DynamicCharacter('Tet_Name', color="#0B610B")
define Lu = Character('Lu_Name', color="#0B610B")
label start:
"It's already our one year anniversary..."
"And I have no idea what I'm going to do."
$ Tet_Name = "Tet"
Tet "Darn, why didn't I check my calendar earlier?"
Re: Code for defining custom character name not working
Posted: Thu Oct 02, 2014 3:17 pm
by Akuni
Oh my gosh~ works like a charm now. Thanks for that bit of info yuucie~!! Appreciate it (*^▽^)/・*:.。.♥.。.:*・