Choosing Character Gender

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
HFSaber
Newbie
Posts: 9
Joined: Thu Jul 19, 2018 4:37 pm
Projects: Cupid's Bow, Star Crossed
Deviantart: HFSaber
Contact:

Choosing Character Gender

#1 Post by HFSaber »

Hello! I'm relatively new to coding with Python, but I do have some experience with JavaScript. I feel like that's important.

I tried to watch a tutorial on choosing a character at the start of the game, but I feel like what the creator had doesn't really fit my situation (plus, they're using an older version of Ren'Py). I'm not sure how to make the code remember the character's choice for gender. This is the code I have for this section:

Code: Select all

python:
        player = renpy.input(_("What is your name?"))

        player= player.strip() or __("Noel")

    label gender:
        'What are your pronouns?'

        menu Choice:
            "He/Him":
                jump gender_male
            "She/Her":
                jump gender_female
            "They/Them":
                jump gender_neutral

        label gender_male:
            show mc_male
            'Are you male?'

            menu:
                "Yes":
                    "Test"
                "No":
                    jump gender

        label gender_female:
            show mc_female
            'Are you female?'

            menu:
                "Yes":
                    "Test."
                "No":
                    jump gender

        label gender_neutral:
            show mc_neutral
            'Are you neither?'

            menu:
                "Yes":
                    "Test."
                "No":
                    jump gender
Last edited by HFSaber on Thu Jul 19, 2018 7:44 pm, edited 1 time in total.

User avatar
gamerbum
Regular
Posts: 128
Joined: Fri Sep 18, 2015 4:40 pm
Projects: Our Lovely Escape, Mizari Loves Company
Organization: Reine Works
Tumblr: reineworks
Location: Canada
Contact:

Re: Choosing Character Gender

#2 Post by gamerbum »

You should be using variables for this, not labels. https://www.renpy.org/wiki/renpy/doc/tu ... er_Choices

Example:
define gender = 0

label start:

'What are your pronouns?'

menu:
"He/Him":
$ gender = 1
"She/Her":
$ gender = 2
"They/Them":
$ gender = 3
And then to call your variables, you need to do it like so (but with proper Ren'Py space syntax)...
if gender == 1:
"I'm a man."
elif gender == 2:
"I'm a woman."
elif gender == 3:
"I'm agender."

HFSaber
Newbie
Posts: 9
Joined: Thu Jul 19, 2018 4:37 pm
Projects: Cupid's Bow, Star Crossed
Deviantart: HFSaber
Contact:

Re: Choosing Character Gender

#3 Post by HFSaber »

I was just using the labels to go the confirmation question so that the player can see the character sprite for the gender they chose, or if they accidentally misclicked, they can go back to the original question. I had a feeling it had something to do with variables, but I wasn't sure how variables worked in Python. Thank you!

philat
Eileen-Class Veteran
Posts: 1900
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Choosing Character Gender

#4 Post by philat »

default, not define. define is for constants (as opposed to variables).

Code: Select all

default gender = None

label start:
    python:
        player = renpy.input(_("What is your name?"))

        player= player.strip()
        if player == "": # I assume Noel is a default only if the player did not enter anything
            player = __("Noel")

    menu choose_gender: # probably makes more sense to have the question in the menu and to jump directly to the menu
        'What are your pronouns?'

        "He/Him":
            $ gender = "male"
        "She/Her":
            $ gender = "female"
        "They/Them":
            $ gender = "neutral"

    show expression "mc_" + gender # show mc_male, mc_female, or mc_neutral
    "Are you [gender]"?

    menu:
        "Yes":
            "Okay."
        "No":
            jump choose_gender

    "Next stuff."

HFSaber
Newbie
Posts: 9
Joined: Thu Jul 19, 2018 4:37 pm
Projects: Cupid's Bow, Star Crossed
Deviantart: HFSaber
Contact:

Re: Choosing Character Gender

#5 Post by HFSaber »

Can you elaborate a bit on the [show expression "mc_" + gender # show mc_male, mc_female, or mc_neutral] part? What am I supposed to do there?

philat
Eileen-Class Veteran
Posts: 1900
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Choosing Character Gender

#6 Post by philat »

...nothing? Just copy paste it and try it. Documentation is here if you're curious. https://www.renpy.org/doc/html/displayi ... -statement (scroll down to Show Expression).

HFSaber
Newbie
Posts: 9
Joined: Thu Jul 19, 2018 4:37 pm
Projects: Cupid's Bow, Star Crossed
Deviantart: HFSaber
Contact:

Re: Choosing Character Gender

#7 Post by HFSaber »

Wait, so I can just leave it like that and it'll show the proper sprite?

philat
Eileen-Class Veteran
Posts: 1900
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Choosing Character Gender

#8 Post by philat »

Have you tried it?

HFSaber
Newbie
Posts: 9
Joined: Thu Jul 19, 2018 4:37 pm
Projects: Cupid's Bow, Star Crossed
Deviantart: HFSaber
Contact:

Re: Choosing Character Gender

#9 Post by HFSaber »

I guess I was just amazed that it was that simple. I was looking for a way to shorthand it that didn't involve a whole bunch of if and elif statements, so thank you very much!

User avatar
gamerbum
Regular
Posts: 128
Joined: Fri Sep 18, 2015 4:40 pm
Projects: Our Lovely Escape, Mizari Loves Company
Organization: Reine Works
Tumblr: reineworks
Location: Canada
Contact:

Re: Choosing Character Gender

#10 Post by gamerbum »

philat wrote: Thu Jul 19, 2018 9:30 pm default, not define. define is for constants (as opposed to variables).

Code: Select all

default gender = None

label start:
    python:
        player = renpy.input(_("What is your name?"))

        player= player.strip()
        if player == "": # I assume Noel is a default only if the player did not enter anything
            player = __("Noel")

    menu choose_gender: # probably makes more sense to have the question in the menu and to jump directly to the menu
        'What are your pronouns?'

        "He/Him":
            $ gender = "male"
        "She/Her":
            $ gender = "female"
        "They/Them":
            $ gender = "neutral"

    show expression "mc_" + gender # show mc_male, mc_female, or mc_neutral
    "Are you [gender]"?

    menu:
        "Yes":
            "Okay."
        "No":
            jump choose_gender

    "Next stuff."
Both ways work, actually. It's very much a pick-your-poison thing. On a personal level, I prefer custom tailoring gender-based sentences and small sections of scenes, rather than just switching out pronouns (which will also need their own sets of variables for each mention). But to each their own.

philat
Eileen-Class Veteran
Posts: 1900
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Choosing Character Gender

#11 Post by philat »

If you're talking about default/define, that's actually not true. Variables set with define will often cause save/load issues if they are changed after being set during init. https://www.renpy.org/doc/html/python.h ... -statement Further discussion in a recent thread: viewtopic.php?f=8&t=50964

For your second point, that's fair. There are many cases where explicit if/elses would be more appropriate. In the OP's example, however, only the image and the last word changed for each label, so it was easily collapsible, so I wanted to point that out.

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: Choosing Character Gender

#12 Post by Remix »

Just to add to this, it maybe better to define just one image tag set and add a variable part rather than mc_male, mc_female etc:

image mc = "images/mc_[gender].png"

(or even a Composite or LayeredImage using the gender interpolation)
Frameworks & Scriptlets:

Post Reply

Who is online

Users browsing this forum: No registered users