[SOLVED]Can you assign your main character two names?

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
Monochrome.Cherry
Regular
Posts: 38
Joined: Thu Jul 24, 2014 6:11 am
Projects: mirroreD≒dREAMS ~Alternate~, NOTES
Tumblr: magicalstarrycarnival
Deviantart: silky-starry-heart
itch: MonochromeCherry
Contact:

[SOLVED]Can you assign your main character two names?

#1 Post by Monochrome.Cherry » Thu Mar 30, 2017 5:46 pm

Hello! I'm really sorry if this is a really noobish question or anything, but I've tried to look everywhere and came up with no exact results for what I was looking for. :oops:

I'm having a bit of trouble trying to assign two names to the protagonist of my story. I want players to have the option of naming the MC if they want to or just leaving her name as the default. Problem is, the way I have it set up is by giving the player an option to name her inside a menu like so:

Code: Select all

    n "Do you want to leave the default name?"
    
    n "Or do you want to input your own name?"
    
     menu:
        "I want to leave the default name":
                                         jump default
        
        "I want to input my own name":
                                         jump yourname
    
    label default:
        n "Default name it is!"
        jump next
        
    label yourname:
       n "Then tell me your name."
       
       $ player_name = renpy.input ("What is your name?", "Heidi")
       $ player_name = f_name.strip()
       if player_name == "":
           $ player_name = "Heidi"
       jump next
I have the MC defined like this for reference:

Code: Select all

define h = Character ("[player_name]")
My problem lies with the fact that I have no idea if you can still refer to the MC with her default name if the player chooses the first option and decides not to name the MC. I can only get it working when I choose the second option to name her since she's defined as [player_name], but I really want to know if you can assign two names to this character so that if you choose the first option and never go into the menu to change her name, you'll only see her default name. I'm really sorry if this seems confusing since I really have no clue how to go about doing this.

Thank you so much for any help!
Last edited by Monochrome.Cherry on Sat Apr 01, 2017 8:59 am, edited 1 time in total.
Image Image

User avatar
sunwave
Regular
Posts: 45
Joined: Fri Apr 15, 2016 2:26 pm
Location: Netherlands
Contact:

Re: Can you assign your main character two names?

#2 Post by sunwave » Thu Mar 30, 2017 6:15 pm

In the choice menu, if you choose the default name option, it will just not change anything. Since you have never given player_name a value, it will not be "Heidi" but just a blank "None". The "Heidi" part in the code you set is only for what is automatically in the textbox for the input section. If you never go through there, it doesn't actually change the value of the variable player_name. So you'll get errors later if you want to use player_name in something else (because it doesn't exist yet).

Just add this BEFORE the "label start" section (and before you define the characters):

Code: Select all

default player_name = "Heidi"
I think that should work. The default action will only make the player_name into "Heidi" if it has nothing yet (so after pressing "new game"). If you load a game, and you put in a different name, it should be fine too.

Watch your indentations. Always use the same distance of 4 spaces (or 1 tab, but that doesn't always work with all editor types). You'll get errors left and right otherwise, sooner or later.

So your final code should be something like this:

Code: Select all

default player_name = "Heidi"
define h = character ("[player_name]")
# And something to define n, which you probably did somewhere here?

label start

    n "Do you want to leave the default name?"
    n "Or do you want to input your own name?"

    menu: # This one is 1 space too much to the right? Don't do that!
        "I want to leave the default name":
            jump default # Don't put this all the way to the right, either!

        "I want to input my own name":
            jump yourname # This one too. Use only 1 indentation (4 spaces) per tier.
    
label default: # Labels generally go to the far left again. Not always, but generally they should.
    n "Default name it is!"
    jump next
        
label yourname:
    n "Then tell me your name."
    $ player_name = renpy.input ("What is your name?", "Heidi")
    $ player_name = player_name.strip() # You had some strange varialbe f_name instead of player_name. Not sure why. Maybe a remnant from something you copied? 
    if player_name == "":
        $ player_name = "Heidi"
    jump next

label next:
    n "Ok, you are now [player_name]!"
Last edited by sunwave on Thu Mar 30, 2017 6:50 pm, edited 3 times in total.

Brandom
Newbie
Posts: 11
Joined: Thu Mar 16, 2017 6:24 pm
Contact:

Re: Can you assign your main character two names?

#3 Post by Brandom » Thu Mar 30, 2017 6:44 pm

I combined the 'custom' name code (input) with picking a random name from a pre-made list if the player decides not to provide a name themselves.
If you'd like, I could share that code? :)

User avatar
Monochrome.Cherry
Regular
Posts: 38
Joined: Thu Jul 24, 2014 6:11 am
Projects: mirroreD≒dREAMS ~Alternate~, NOTES
Tumblr: magicalstarrycarnival
Deviantart: silky-starry-heart
itch: MonochromeCherry
Contact:

Re: Can you assign your main character two names?

#4 Post by Monochrome.Cherry » Sat Apr 01, 2017 8:59 am

sunwave wrote:In the choice menu, if you choose the default name option, it will just not change anything. Since you have never given player_name a value, it will not be "Heidi" but just a blank "None". The "Heidi" part in the code you set is only for what is automatically in the textbox for the input section. If you never go through there, it doesn't actually change the value of the variable player_name. So you'll get errors later if you want to use player_name in something else (because it doesn't exist yet).

Just add this BEFORE the "label start" section (and before you define the characters):

Code: Select all

default player_name = "Heidi"
I think that should work. The default action will only make the player_name into "Heidi" if it has nothing yet (so after pressing "new game"). If you load a game, and you put in a different name, it should be fine too.

Watch your indentations. Always use the same distance of 4 spaces (or 1 tab, but that doesn't always work with all editor types). You'll get errors left and right otherwise, sooner or later.

So your final code should be something like this:

Code: Select all

default player_name = "Heidi"
define h = character ("[player_name]")
# And something to define n, which you probably did somewhere here?

label start

    n "Do you want to leave the default name?"
    n "Or do you want to input your own name?"

    menu: # This one is 1 space too much to the right? Don't do that!
        "I want to leave the default name":
            jump default # Don't put this all the way to the right, either!

        "I want to input my own name":
            jump yourname # This one too. Use only 1 indentation (4 spaces) per tier.
    
label default: # Labels generally go to the far left again. Not always, but generally they should.
    n "Default name it is!"
    jump next
        
label yourname:
    n "Then tell me your name."
    $ player_name = renpy.input ("What is your name?", "Heidi")
    $ player_name = player_name.strip() # You had some strange varialbe f_name instead of player_name. Not sure why. Maybe a remnant from something you copied? 
    if player_name == "":
        $ player_name = "Heidi"
    jump next

label next:
    n "Ok, you are now [player_name]!"
Thank you so much for your help! Your code worked perfectly! Again, thank you so much for your help and the tips! :D
Brandom wrote:I combined the 'custom' name code (input) with picking a random name from a pre-made list if the player decides not to provide a name themselves.
If you'd like, I could share that code? :)
Thank you so much for your offer! I only had one name planned for the protag, but thank you so much anyways!
Image Image

Post Reply

Who is online

Users browsing this forum: Bing [Bot]