Setting narrator name [SOLVED]

Knyghtblade

Newbie
Nov 3, 2017
64
15
Hi all,

So I was wondering if someone might have a solution for this? I have code in my game for the player to select their name. What I would like to do is use that input name to change the name of the charater narrating so it reads '<Player Name> Narrating' as the character name instead of what I have now which is just 'Narrating.'

Here is my code for this:

define m = Character("Dave", who_color="#800080", what_color="#FF7F50")
define n = Character("Narrating", who_color="#0000FF", what_color="#7FFFD4")

$ m = renpy.input("Input your name:", default = str(m))
$ m = m.strip()
if m == "":
$ m = "Dave"

n "The legendary %(m)s !"


Any thoughts?

Cheerss
 
Last edited:

crabsinthekitchen

Well-Known Member
Apr 28, 2020
1,565
9,063
this should work
Code:
define m = Character("[m_name]", who_color="#800080", what_color="#FF7F50")
define n = Character("[m_name] Narrating", who_color="#0000FF", what_color="#7FFFD4")

$ m_name = renpy.input("Input your name:", default = str(m))
$ m_name = m_name.strip()
if m_name == "":
$ m_name = "Dave"
 

Knyghtblade

Newbie
Nov 3, 2017
64
15
this should work
Code:
define m = Character("[m_name]", who_color="#800080", what_color="#FF7F50")
define n = Character("[m_name] Narrating", who_color="#0000FF", what_color="#7FFFD4")

$ m_name = renpy.input("Input your name:", default = str(m))
$ m_name = m_name.strip()
if m_name == "":
$ m_name = "Dave"

I copy pasted the code exactly but I get this error.

```
I'm sorry, but an uncaught exception occurred.

While running game code:
File "game/script.rpy", line 90, in script
$ m_name = renpy.input("Input your name:", default = str(m))
File "game/script.rpy", line 90, in <module>
$ m_name = renpy.input("Input your name:", default = str(m))
KeyError: u'm_name'

-- Full Traceback ------------------------------------------------------------

Full traceback:
File "game/script.rpy", line 90, in script
$ m_name = renpy.input("Input your name:", default = str(m))
File "renpy/ast.py", line 922, in execute
renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
File "renpy/python.py", line 2218, in py_exec_bytecode
exec(bytecode, globals, locals)
File "game/script.rpy", line 90, in <module>
$ m_name = renpy.input("Input your name:", default = str(m))
File "renpy/character.py", line 1032, in __unicode__
return renpy.substitutions.substitute(who)[0]
File "renpy/substitutions.py", line 270, in substitute
s = formatter.vformat(s, (), kwargs)
File "/home/tom/ab/renpy-build/tmp/install.linux-x86_64/lib/python2.7/string.py", line 563, in vformat
File "/home/tom/ab/renpy-build/tmp/install.linux-x86_64/lib/python2.7/string.py", line 585, in _vformat
File "/home/tom/ab/renpy-build/tmp/install.linux-x86_64/lib/python2.7/string.py", line 646, in get_field
File "/home/tom/ab/renpy-build/tmp/install.linux-x86_64/lib/python2.7/string.py", line 605, in get_value
KeyError: u'm_name'
 

recreation

pure evil!
Respected User
Game Developer
Jun 10, 2018
6,327
22,773
default mn = "[m] [n]" in combination with your code should work.
then when your character is narrating use mn instead of m as the name.
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,607
2,256
Hmmm....

RenPy has a special Character() for narration. It's imaginatively called narrator.

Anytime you use dialogue without specifying who is speaking, it's uses narrator.
It's there by default, which is why you don't normally see it specified in most games. But you can override it.

Python:
default mc_name = "Unnamed"

define narrator = Character("The Narrator")

define mc = Character("[mc_name]")
define e = Character("Emily", color="#04B486")
define k = Character("Karen", color="#04B486")
define c = Character("Claire", color="#04B486")

label start:

    scene black with fade

    $ mc_name = renpy.input("What is your name? {i}(Press ENTER for 'Peter'){/i}")
    $ mc_name = mc_name.strip() or "Peter"

    mc "Hi. My name is [mc]."
    e "And I'm [e], and this is my sister, [k]."
    k "Hi."
    c "And I'm their friend [c]."

    "Welcome to their story." # this is narration by the "narrator" character.

    "*** THE END ***" # so is this... !!!
    return

Though based on your example, I think you'd probably want...

define narrator = Character("[mc_name] Narrating")
 
  • Like
Reactions: anne O'nymous