Page 1 of 1

[solved] name switching

Posted: Sat Jan 09, 2021 12:18 am
by The King
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 :)

Re: name switching

Posted: Sat Jan 09, 2021 1:04 am
by _ticlock_
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.

Re: name switching

Posted: Sat Jan 09, 2021 9:21 pm
by The King
Okay, I think everything's working just as I wanted it to. Thank you for your help. :)