Player Character Name

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
themocaw
Regular
Posts: 106
Joined: Mon Aug 06, 2007 10:58 am
Contact:

Player Character Name

#1 Post by themocaw »

Okay, here it is: I'd like to be able to let the player enter their own name and use it as the name of the player character in my ren'ai game. I'm sure someone has done this already. Can anyone point me to the correct tutorial or forum post? Thank you :)

Dis
Regular
Posts: 33
Joined: Sat Apr 22, 2006 6:00 am
Projects: Angel of Love,Forgotten,War's Fate, D
Location: Hungary
Contact:

Re: Player Character Name

#2 Post by Dis »

Where there's a will there's a way.

Project D:AoL
Special Thanks for their motivation and support to: BCS, Enerccio, mikey, monele, PyTom, yvanc, mugenjohncel, Sai

themocaw
Regular
Posts: 106
Joined: Mon Aug 06, 2007 10:58 am
Contact:

Re: Player Character Name

#3 Post by themocaw »

Thanks. :) Thinking something like this should probably be added to the cookbook for us n00bs.

themocaw
Regular
Posts: 106
Joined: Mon Aug 06, 2007 10:58 am
Contact:

Re: Player Character Name

#4 Post by themocaw »

I'm having trouble getting the code to work properly. What I want to do is have the character enter their first and last names in the program, and then plug the values into the conversations and into the text headers. The first part works fine, the second part not so well.

Here are the relevant lines of code.

Code: Select all

init:
    $ a = Character('%(firstname)s', color ="#5F9F9F")
    $ a2 = Character('Little %(firstname)s', color ="#5F9F9F")

label start:
    $ firstname = renpy.input ("What's your first name?", "Alex", length=20)
    $ lastname = renpy.input ("What's your last name?", "Quill", length=20)

    a "I dunno, I mean, why do we have to agree to this?"
The game returns:

Image


So what am I doing wrong here?

monele
Lemma-Class Veteran
Posts: 4101
Joined: Sat Oct 08, 2005 7:57 am
Location: France
Contact:

Re: Player Character Name

#5 Post by monele »

Mmm... you'll have to use the "dynamic" parameter of Character for this, but I think it's limited to a single variable :

Code: Select all

init:
    p = Character("firstname", dynamic=True)

label start:
    $ firstname = "Paul"
    p "Lalala."
Now, if you want to have something like "Little Paul" displayed, you should make another Character pointing to, for example, "littlefirstname" and set littlefirstname as a combination of "Little " and firstname :

Code: Select all

$ littlefirstname = "Little " + firstname
(my python is rusty, if it's not "+", it might be "&")

J13
Regular
Posts: 60
Joined: Wed Jan 24, 2007 3:28 am
Location: Cambridge
Contact:

Re: Player Character Name

#6 Post by J13 »

There's also a section (User interaction) in the Ren'py demo that seems to do exactly what you want to do.
You could always go into that section of the demo, click the button in the top right and see how it was done.

themocaw
Regular
Posts: 106
Joined: Mon Aug 06, 2007 10:58 am
Contact:

Re: Player Character Name

#7 Post by themocaw »

Thank you both :) I didn't really think of taking a look at the demo like that. . . to be honest, I barely even looked at it before reading up on the tutorials and trying to figure things out :P I know, I know, RTMF.

Criptych
Regular
Posts: 87
Joined: Sat Jun 23, 2007 9:19 am
Projects: ALICE.NET
Location: The other end of the internet.
Contact:

Re: Player Character Name

#8 Post by Criptych »

monele wrote:Mmm... you'll have to use the "dynamic" parameter of Character for this, but I think it's limited to a single variable :
Not necessarily. "If [the dynamic argument to Character is] true, then name is interpreted as a string containing a python expression that is evaluated to yield the name of the character."

I tried the following code (using some resources from the Ren'Py Demo) and it works nicely:

Code: Select all

init:
    image bg washington = "washington.jpg"

    image eileen happy = "eileen_happy.png"
    image eileen vhappy = "eileen_vhappy.png"
    image eileen concerned = "eileen_concerned.png"

    $ e = Character('knows_eileen and "Eileen" or "???"', dynamic=True, color="#c8ffc8")

label start:
    $ knows_eileen = False
    
    scene bg washington
    show eileen happy
    with dissolve

    e "Hi! We're testing some uses of DynamicCharacter."

    show eileen concerned
    with dissolve

    e "What? We haven't met?"

    show eileen happy
    with dissolve

    $ knows_eileen = True
    
    extend "  Well, my name's Eileen."
    
    show eileen vhappy
    with dissolve

    e "It's a pleasure to meet you!"

    scene black
    with dissolve

    return
For your case, try something like this:

Code: Select all

init:
    $ a = Character('firstname', dynamic=True, color ="#5F9F9F")
    $ a2 = Character('"Little "+firstname', dynamic=True, color ="#5F9F9F")
Computers are useless. They can only give you answers. —Pablo Picasso

Image

monele
Lemma-Class Veteran
Posts: 4101
Joined: Sat Oct 08, 2005 7:57 am
Location: France
Contact:

Re: Player Character Name

#9 Post by monele »

Cool, I didn't expect a full python expression was possible ^_^

Criptych
Regular
Posts: 87
Joined: Sat Jun 23, 2007 9:19 am
Projects: ALICE.NET
Location: The other end of the internet.
Contact:

Re: Player Character Name

#10 Post by Criptych »

monele wrote:Cool, I didn't expect a full python expression was possible ^_^
I'd bet you could even use a function call, if the need arose. Oh, the possibilities...! :mrgreen:
Computers are useless. They can only give you answers. —Pablo Picasso

Image

User avatar
PyTom
Ren'Py Creator
Posts: 16097
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Player Character Name

#11 Post by PyTom »

Yes, you can use any python expression, provided you quote it correctly.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Criptych
Regular
Posts: 87
Joined: Sat Jun 23, 2007 9:19 am
Projects: ALICE.NET
Location: The other end of the internet.
Contact:

Re: Player Character Name

#12 Post by Criptych »

PyTom wrote:Yes, you can use any python expression, provided you quote it correctly.
But that's the fun part!

*still trying to think of uses for function calls in DynamicCharacter*
Computers are useless. They can only give you answers. —Pablo Picasso

Image

Post Reply

Who is online

Users browsing this forum: No registered users