Using multiple names for one character?

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
10+5
Newbie
Posts: 2
Joined: Tue Aug 04, 2020 5:44 pm
Contact:

Using multiple names for one character?

#1 Post by 10+5 »

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.

anonymouse
Newbie
Posts: 23
Joined: Wed Oct 10, 2018 4:32 pm
Contact:

Re: Using multiple names for one character?

#2 Post by anonymouse »

This is actually super easy. Here's working code!

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
For more details, check the documentation here:

https://renpy.org/doc/html/dialogue.htm ... #Character

User avatar
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?

#3 Post by Remix »

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
Frameworks & Scriptlets:

User avatar
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?

#4 Post by ghostclown »

Nice, that's a much smarter way than how I was doing it.

User avatar
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?

#5 Post by ghostclown »

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
Hm, when I try this it displays the name as [u'Bob'], basically, and the name doesn't change when the variable does.

(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


define pc = Character(_("Bob"))

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.

User avatar
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?

#6 Post by Remix »

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.
Frameworks & Scriptlets:

User avatar
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?

#7 Post by ghostclown »

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.

10+5
Newbie
Posts: 2
Joined: Tue Aug 04, 2020 5:44 pm
Contact:

Re: Using multiple names for one character?

#8 Post by 10+5 »

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
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!

Post Reply

Who is online

Users browsing this forum: Kocker, Semrush [Bot], VESTED