Using multiple names for one character?
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.
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.
Using multiple names for one character?
Hi all,
I'm working on a visual novel where a character uses multiple names/aliases at various points in the story, and was wondering what the easiest way to switch between these names might be.
A friend familiar with Python came up with this piece of code for me, but it doesn't seem to work:
init python:
PC_NAME = "charname"
def setPCToX():
global PC_NAME
PC_NAME = "X"
def setPCToY():
global PC_NAME
def setPCToZ():
global PC_NAME
PC_NAME = "Z"
def setPCToQ():
global PC_NAME
PC_NAME = "???"
Ideally what I want is to be able to change names with a simple command and without changing characters: for example, to set character y's name to display as "x" when undercover or as "???" before their introduction. I'm not sure if it's easier to just use different characters, but that seems to me like it's a bit of a clunkier solution? I wouldn't know, this is my first time trying to code anything outside of basic HTML!
Sorry for the total noob question, but I'm really struggling to find anything about this elsewhere and I wondered if someone might be able to help! Even a link to a relevant part of the documentation would be a godsend. Thank you so much in advance.
I'm working on a visual novel where a character uses multiple names/aliases at various points in the story, and was wondering what the easiest way to switch between these names might be.
A friend familiar with Python came up with this piece of code for me, but it doesn't seem to work:
init python:
PC_NAME = "charname"
def setPCToX():
global PC_NAME
PC_NAME = "X"
def setPCToY():
global PC_NAME
def setPCToZ():
global PC_NAME
PC_NAME = "Z"
def setPCToQ():
global PC_NAME
PC_NAME = "???"
Ideally what I want is to be able to change names with a simple command and without changing characters: for example, to set character y's name to display as "x" when undercover or as "???" before their introduction. I'm not sure if it's easier to just use different characters, but that seems to me like it's a bit of a clunkier solution? I wouldn't know, this is my first time trying to code anything outside of basic HTML!
Sorry for the total noob question, but I'm really struggling to find anything about this elsewhere and I wondered if someone might be able to help! Even a link to a relevant part of the documentation would be a godsend. Thank you so much in advance.
-
- Newbie
- Posts: 23
- Joined: Wed Oct 10, 2018 4:32 pm
- Contact:
Re: Using multiple names for one character?
This is actually super easy. Here's working code!
For more details, check the documentation here:
https://renpy.org/doc/html/dialogue.htm ... #Character
Code: Select all
default e = Character("Eileen") # use default instead of define so any name changes are persistent on save/load
label start:
e "Now you see me!"
$ e.name = "???" # this changes the name property of the character object
e "Now you don't!"
return
https://renpy.org/doc/html/dialogue.htm ... #Character
- Remix
- Eileen-Class Veteran
- Posts: 1628
- Joined: Tue May 30, 2017 6:10 am
- Completed: None... yet (as I'm still looking for an artist)
- Projects: An un-named anime based trainer game
- Contact:
Re: Using multiple names for one character?
As anonymouse says, you do not really need a function to adjust the name.
I would though suggest using a dynamic character to adjust the name...
I would though suggest using a dynamic character to adjust the name...
Code: Select all
default pc_name = _("Bob") ## the _() sets it for translation
define pc = Character("[pc_name]") # use [] interpolation to make this character dynamic
label start:
pc "I am"
$ pc_name = _("Sam") # this changes the name (and adds Sam to translations)
pc "I still am... just different"
return
Frameworks & Scriptlets:
- Speech Bubble dialogue system
- Multiple Notify with ATL and history
- (WIP) Radial Masking - needs updating to use Shader
- 7.4 - Smooth Tinting using ATL and matrixcolor
- Several other repositories there too
- ghostclown
- Regular
- Posts: 28
- Joined: Sun Oct 11, 2020 2:33 pm
- Projects: R. I. P. Tour
- itch: ghostclown
- Contact:
Re: Using multiple names for one character?
Nice, that's a much smarter way than how I was doing it.
- ghostclown
- Regular
- Posts: 28
- Joined: Sun Oct 11, 2020 2:33 pm
- Projects: R. I. P. Tour
- itch: ghostclown
- Contact:
Re: Using multiple names for one character?
Hm, when I try this it displays the name as [u'Bob'], basically, and the name doesn't change when the variable does.Remix wrote: ↑Sat Oct 17, 2020 5:20 am As anonymouse says, you do not really need a function to adjust the name.
I would though suggest using a dynamic character to adjust the name...
Code: Select all
default pc_name = _("Bob") ## the _() sets it for translation define pc = Character("[pc_name]") # use [] interpolation to make this character dynamic label start: pc "I am" $ pc_name = _("Sam") # this changes the name (and adds Sam to translations) pc "I still am... just different" return
(It also got mad about the name variable not being declared, but that was easily fixed by changing them both to default)
So maybe something more along the lines of
label start:
pc "I am"
$ pc.name = _("Sam")
pc "I still am... just different"
return
EDIT: Don't do it this way. As far as I can tell, it doesn't seem to persist after saving and loading files.
Last edited by ghostclown on Tue Oct 20, 2020 3:51 pm, edited 1 time in total.
- Remix
- Eileen-Class Veteran
- Posts: 1628
- Joined: Tue May 30, 2017 6:10 am
- Completed: None... yet (as I'm still looking for an artist)
- Projects: An un-named anime based trainer game
- Contact:
Re: Using multiple names for one character?
Works perfectly here so I presume you changed things when you tried it.
If you want to test, just try it in a fresh project.
If you want to test, just try it in a fresh project.
Frameworks & Scriptlets:
- Speech Bubble dialogue system
- Multiple Notify with ATL and history
- (WIP) Radial Masking - needs updating to use Shader
- 7.4 - Smooth Tinting using ATL and matrixcolor
- Several other repositories there too
- ghostclown
- Regular
- Posts: 28
- Joined: Sun Oct 11, 2020 2:33 pm
- Projects: R. I. P. Tour
- itch: ghostclown
- Contact:
Re: Using multiple names for one character?
Probably. I'd tried adding it to my current project. I'll keep debugging.
EDIT: You're totally right. No idea what I messed up before, but yeah it absolutely works.
EDIT: You're totally right. No idea what I messed up before, but yeah it absolutely works.
Re: Using multiple names for one character?
Thank you so much, this worked like a charm! One question, when changing the name back to the default, do I just use the same "pc_name =_("x")" or is there a more condensed way to change it back? Sorry for the beginner-level questions and thank you so much again!Remix wrote: ↑Sat Oct 17, 2020 5:20 am As anonymouse says, you do not really need a function to adjust the name.
I would though suggest using a dynamic character to adjust the name...
Code: Select all
default pc_name = _("Bob") ## the _() sets it for translation define pc = Character("[pc_name]") # use [] interpolation to make this character dynamic label start: pc "I am" $ pc_name = _("Sam") # this changes the name (and adds Sam to translations) pc "I still am... just different" return