NPC name change after identification

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
Bum_McFluff
Regular
Posts: 45
Joined: Sat Aug 18, 2018 8:15 pm
Contact:

NPC name change after identification

#1 Post by Bum_McFluff » Sat May 01, 2021 7:54 pm

I want some of my NPCs to simply be called "maid", or "delivery boy" etc until they actually say something like "my name is John". After that point their names would show as "John". I thought I could do it this way, but I keep getting an error.

I set up what I hoped would be the name
character.rpy

Code: Select all

define m = Character("[Hotelmaid]", image="hotelmaid")
I added the variables for before and after the identification:
variables.rpy

Code: Select all

label variables:

    $ nameHotelmaid = False
    if nameHotelmaid == False:
        [Hotelmaid] = "maid"
    else:
        [Hotelmaid] = "Marie"

    return
I let the script call the variables:
script.rpy

Code: Select all

label start:

    call variables

    call intro_scene

label end_intro:

    call hotel_01_scene

label end_hotel_01:

    "Where to now?"

    return
And finally in the content, I added this:

Code: Select all

    m "No problem. Just call if you waant anything. My name is Marie."
    $ nameHotelmaid = True
But when I run it, I keep seeing this:

Parsing the script failed.

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.

File "game/variables.rpy", line 6: expected statement.
    [Hotelmaid] = "maid"
                ^
File "game/variables.rpy", line 8: expected statement.
    [Hotelmaid] = "Marie"
                ^

Ren'Py Version: Ren'Py 7.4.4.1439
Sun May  2 09:48:51 2021
I am no expert in Ren'Py so please forgive what is probably a rookie mistake, but I don't know what it is.
What, spy on our spy as he searches for their spy? Why not, sounds rather like fun.

User avatar
emz911
Regular
Posts: 103
Joined: Fri Jun 23, 2017 2:23 pm
Contact:

Re: NPC name change after identification

#2 Post by emz911 » Sat May 01, 2021 9:05 pm

You’d want to define the character as Dynamic and remove the brackets, this way it will know to pull the name from a variable:

Code: Select all

define m = DynamicCharacter("m_name")
#or another way of writing this as documented is:
define m = Character(“m_name”, dynamic=True)
Don’t forget to define the variable m_name first! Then whenever you need to change the name, just do

Code: Select all

$ m_name = “Marie”
You did it right for the other variable, it’s no different :mrgreen:

User avatar
Bum_McFluff
Regular
Posts: 45
Joined: Sat Aug 18, 2018 8:15 pm
Contact:

Re: NPC name change after identification

#3 Post by Bum_McFluff » Sat May 01, 2021 11:22 pm

If the dynamic = True is for the name "Marie", how do I show the "Maid" name before she identifies herself. Do I keep everything:

Code: Select all

label variables:

    $ nameHotelmaid = False
    if nameHotelmaid == False:
        [Hotelmaid] = "maid"
    else:
        [Hotelmaid] = "Marie"

    return
but just change the nameHotelmaid to m_name?
What, spy on our spy as he searches for their spy? Why not, sounds rather like fun.

User avatar
emz911
Regular
Posts: 103
Joined: Fri Jun 23, 2017 2:23 pm
Contact:

Re: NPC name change after identification

#4 Post by emz911 » Sun May 02, 2021 12:08 am

Maybe I confused you by changing your variable name, sorry about that, but the m_name is supposed to equal to your Hotelmaid variable. To be clearer, I’ll use your variables:

Code: Select all

#Define your default variables here
default nameHotelmaid = False
default Hotelmaid = "maid"

#Define your characters, note that those brackets were removed
define m = Character("Hotelmaid", image="hotelmaid", dynamic=True)

label variables:
    #Simply change the Hotelmaid variable in your label and the character name will change with it
    if nameHotelmaid == False:
        $ Hotelmaid = "maid"
    else:
        $ Hotelmaid = "Marie"

    return
This is what you have now, but since the character name is directly associated to its variable (Hotelmaid), you won’t even need the if nameHotelmaid == False statement anymore, simply changing the Hotelmaid variable would immediately change the character name. Thus remove the nameHotelmaid variable entirely, and the code can be simplified to:

Code: Select all

default Hotelmaid = "maid"

define m = Character("Hotelmaid", image="hotelmaid", dynamic=True)

label whereverthisis:
    m "No problem. Just call if you waant anything. My name is Marie."
    $ Hotelmaid = "Marie"
You won’t need the “label variable” as well.

User avatar
Bum_McFluff
Regular
Posts: 45
Joined: Sat Aug 18, 2018 8:15 pm
Contact:

Re: NPC name change after identification

#5 Post by Bum_McFluff » Sun May 02, 2021 12:44 am

Thank you, that works perfectly. I have no doubt that I will have another equally stupid question for you later. :)
What, spy on our spy as he searches for their spy? Why not, sounds rather like fun.

User avatar
emz911
Regular
Posts: 103
Joined: Fri Jun 23, 2017 2:23 pm
Contact:

Re: NPC name change after identification

#6 Post by emz911 » Sun May 02, 2021 1:59 pm

I’m glad to help! I do recommend reading through the documentations though, understanding the mechanics and logic behind them would help a lot. You can look up any keyword there, but for this forum particularly, this page deals with basic variables: https://www.renpy.org/doc/html/python.html

Post Reply

Who is online

Users browsing this forum: No registered users