Code for defining custom character name not working

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
ljnicolson
Newbie
Posts: 3
Joined: Sat Sep 27, 2014 1:34 pm
Projects: Occasio Nova Secunda
Location: USA
Contact:

Code for defining custom character name not working

#1 Post 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!

User avatar
Kate
Regular
Posts: 197
Joined: Thu Sep 19, 2013 6:10 pm
Projects: Blackout
Organization: Moonlight Otome
Location: United States
Contact:

Re: Code for defining custom character name not working

#2 Post by Kate »

That is a really complicated way of doing that :o

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.
Current Project:
Blackout [VN][Romance][GxB][Mystery][Suspense] http://lemmasoft.renai.us/forums/viewto ... 43&t=34118
"It is the duty of authors to make the fantastic seem ordinary and the ordinary seem fantastic." - K. Auer

User avatar
ljnicolson
Newbie
Posts: 3
Joined: Sat Sep 27, 2014 1:34 pm
Projects: Occasio Nova Secunda
Location: USA
Contact:

Re: Code for defining custom character name not working

#3 Post 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?

User avatar
78909087
Veteran
Posts: 277
Joined: Sat Aug 16, 2014 2:33 pm
Completed: Dungeons and Don't Do It, Wake Up
Projects: Lethe
IRC Nick: Pacermist
Contact:

Re: Code for defining custom character name not working

#4 Post 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.)
I am not friends with the sun.
Image

User avatar
ljnicolson
Newbie
Posts: 3
Joined: Sat Sep 27, 2014 1:34 pm
Projects: Occasio Nova Secunda
Location: USA
Contact:

Re: Code for defining custom character name not working

#5 Post by ljnicolson »

And that one worked! Thank you so much!

User avatar
78909087
Veteran
Posts: 277
Joined: Sat Aug 16, 2014 2:33 pm
Completed: Dungeons and Don't Do It, Wake Up
Projects: Lethe
IRC Nick: Pacermist
Contact:

Re: Code for defining custom character name not working

#6 Post by 78909087 »

You're welcome :D
I'm glad I could be of assistance.
I am not friends with the sun.
Image

Akuni
Regular
Posts: 40
Joined: Wed Dec 07, 2011 7:06 pm
Location: REDACTED
Contact:

Re: Code for defining custom character name not working

#7 Post 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.

Image

Image

But when I make them normal characters the colour changes apply. I'm not sure if I'm doing something wrong or :c

User avatar
yuucie
Regular
Posts: 164
Joined: Sun Jun 22, 2014 4:04 am
Completed: NaNoReNo[2015] Those Without Names
Tumblr: an-na-ko
Location: Toronto, Canada
Contact:

Re: Code for defining custom character name not working

#8 Post 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.

Image

Image

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

Code: Select all

$ Tet = "Tet"
but you wrote

Code: Select all

$ T = "Tet"
which means you created a new variable over-riding your character's variable.

Akuni
Regular
Posts: 40
Joined: Wed Dec 07, 2011 7:06 pm
Location: REDACTED
Contact:

Re: Code for defining custom character name not working

#9 Post by Akuni »

Code: Select all

define CHARNME2 = DynamicCharacter('NM2', color="#0B610B")
define CHARNME = Character('NM', color="#0B610B")


label start:
    
    [REDACTED TEXT]
    
    $ REDACTED NAME = "REDACTED NAME" 

    [REDACTED TEXT] 
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 >.<
Last edited by Akuni on Mon Mar 13, 2023 7:42 am, edited 1 time in total.

User avatar
yuucie
Regular
Posts: 164
Joined: Sun Jun 22, 2014 4:04 am
Completed: NaNoReNo[2015] Those Without Names
Tumblr: an-na-ko
Location: Toronto, Canada
Contact:

Re: Code for defining custom character name not working

#10 Post 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?"

    

Akuni
Regular
Posts: 40
Joined: Wed Dec 07, 2011 7:06 pm
Location: REDACTED
Contact:

Re: Code for defining custom character name not working

#11 Post by Akuni »

Oh my gosh~ works like a charm now. Thanks for that bit of info yuucie~!! Appreciate it (*^▽^)/・*:.。.♥.。.:*・

Post Reply

Who is online

Users browsing this forum: Google [Bot]