[solved] name switching

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
The King
Regular
Posts: 35
Joined: Fri Sep 25, 2020 12:37 pm
Completed: 0
Projects: LB
Contact:

[solved] name switching

#1 Post by The King » Sat Jan 09, 2021 12:18 am

Hello, I have a new question. As you might have read, this is about name switching, particularly player name switching. This is the current code I've been using for the player names:

define m_name_default = "Joseph" #define the default names
define f_name_default = "Erika"
default m_name = m_name_default #assign the default names as the initial names during the start of the game
default f_name = f_name_default
define m = Character("[m_name]") #use the name variables as the character names
define f = Character("[f_name]")
label name_input: #create a label that we can call to input the name
menu:
"Male":
$ is_male = True #create and set a variable depending on the chosen gender
"Female":
$ is_male = False
$ input = renpy.input("What is your name?").strip() # .strip() removes any trailing or leading white spaces in the user's input
if is_male: # if gender is male we will assign the input to the m_name variable
$ m_name = input if input else m_name_default # if input is not empty then use it, otherwise default to the default name
else:
$ f_name = input if input else f_name_default
return
label start:
"Male name: [m], Female name: [f]"
jump main

Here's what I was hoping to be able to do. I want, at some point to have another character give your player character a nickname, 'Boy' for the male and 'Girl' for the female. I don't want the game to get rid of the player entered names though, because these nicknames will only be temporary. Is there a way to make the game switch between the nickname and the original name without deleting the original name? If so, how could I do this? Please help me, thank you :)
Last edited by The King on Sat Jan 09, 2021 9:22 pm, edited 1 time in total.

User avatar
_ticlock_
Veteran
Posts: 393
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: name switching

#2 Post by _ticlock_ » Sat Jan 09, 2021 1:04 am

Hi, The King,

1) If you want to assign the default names as the initial names during the start of the game you don't need define m_name_default, just:

Code: Select all

default m_name = "Joseph"
default f_name = "Erika"
2) If you want to dynamically change the character name, you should use dynamic property:

Code: Select all

define m = Character("m_name", dynamic=True)
label start:
    m "My current name is [m_name]"
    $ input = renpy.input("What is your name?").strip()
    $ m_name = input if input != "" else m_name # If input == "" m_name won't be changed i.e. m_name == "Joseph"
    m "My current name is [m_name]"
3) Nicknames and other names. This can be approached differently. Some people prefer to create several characters with all names for a single character. You can also store all nicknames in appropriate variables, and change the names as needed.

Code: Select all

define m = Character("m_name", dynamic=True)
define m2 = Character("Boy")

Code: Select all

default m_name_full = "Joseph"
default m_name_nickname = "Boy"
define m = Character("m_name", dynamic=True)

label start:
    $ m_name = m_name_full
    m "My current name is [m_name]"
    $ m_name = m_name_nickname
    m "My current name is [m_name]"
For better organization, you can store names as class attributes for some user-defined character_person class and have some method that defines which name should be currently used.

User avatar
The King
Regular
Posts: 35
Joined: Fri Sep 25, 2020 12:37 pm
Completed: 0
Projects: LB
Contact:

Re: name switching

#3 Post by The King » Sat Jan 09, 2021 9:21 pm

Okay, I think everything's working just as I wanted it to. Thank you for your help. :)

Post Reply

Who is online

Users browsing this forum: No registered users