Character Gender Select Problem/Question

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.
Message
Author
User avatar
Bryy
Veteran
Posts: 407
Joined: Thu Dec 20, 2012 10:12 pm
Completed: 30+ games so far
Projects: Furry Shakespeare
Organization: Stegalosaurus Game Development
Location: Portage, MI
Contact:

Character Gender Select Problem/Question

#1 Post by Bryy »

I'm trying to set up a gender selection system in my next game:

Code: Select all

label chara_select:
    whc "Are you a girl or a boy?"
    menu:
        "Girl":
            $ girl = True
            $ boy = False
            jump start_2
        "Boy":
            $ boy = True
            $ girl = False
            jump start_2
label start_2:
    if girl:
        #PERRY, FEMALE
        image p1 = "TEST_CHARA_2.png" #not done yet
        image p2 = "perry_fem_sad.png"#not done yet
        image p3 = "perry_fem_hurt.png"#not done yet
        image p4 = "perry_fem_happy.png"#not done yet
        image p5 = "perry_fem_angry.png"#not done yet
        image pa1 = "perry_arfem_shocked.png"#not done yet
        image pa2 = "perry_arfem_sad.png"#not done yet
        image pa3 = "perry_arfem_hurt.png"#not done yet
        image pa4 = "perry_arfem_happy.png"#not done yet
        image pa5 = "perry_arfem_angry.png"#not done yet
    if boy:
        #PERRY, MALE
        image p1 = "perry_male_shocked.png"
        image p2 = "perry_male_sad.png"
        image p3 = "perry_male_hurt.png"
        image p4 = "perry_male_happy.png"
        image p5 = "perry_male_angry.png"
        image pa1 = "perry_armale_shocked.png"
        image pa2 = "perry_armale_sad.png"
        image pa3 = "perry_armale_hurt.png"
        image pa4 = "perry_armale_happy.png"
        image pa5 = "perry_armale_angry.png"
    show p1 at left with dissolve
    p "This is so weird."
    jump start
But it just defaults to Male Perry when I select GIRL. I sort of think I know what is going on, but Male Perry's images are all separated in their own block. So I'm a little confused. Help?

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: Character Gender Select Problem/Question

#2 Post by namastaii »

Maybe try to have start_2 jump to a different label depending on the variable. It's possible it's just running through both if statements because there is no break between them and it's overlapping with the last things you changed. So if girl: jump girl_label or something like that and separate them and make sure that the label jumps somewhere else at the end instead of running through continuously. I hope this makes sense. I mean, I KNOW that it shouldn't run the if statement if it's false but just in case it's a problem..

It also could help to put an else statement instead of two if's. I'd try that before anything else.

On another note, it may feel more organized/simpler to have one variable called gender and have it set to 0 or 1 for girl and boy. That's what I've done. But it's just a thought. So you don't have to change two variables. Just one.

User avatar
Bryy
Veteran
Posts: 407
Joined: Thu Dec 20, 2012 10:12 pm
Completed: 30+ games so far
Projects: Furry Shakespeare
Organization: Stegalosaurus Game Development
Location: Portage, MI
Contact:

Re: Character Gender Select Problem/Question

#3 Post by Bryy »

Tried the first two. Didn't work.

Will try the third.

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: Character Gender Select Problem/Question

#4 Post by namastaii »

Hmmm...
yeah I guess just try if gender == 0, etc.

I'm trying to think of what else it could be. For my two genders, I don't change the definition of a lot of images, I have an if statement inside of a composite. Instead of in a label. So the composite is either going to show girl pieces or boy pieces depending on the variable.
I may have even assigned them to their own composites though. I'm not sure.

*edit: I'll try to put together an example when I can and post it here. I'll test it and make sure it works.

User avatar
Bryy
Veteran
Posts: 407
Joined: Thu Dec 20, 2012 10:12 pm
Completed: 30+ games so far
Projects: Furry Shakespeare
Organization: Stegalosaurus Game Development
Location: Portage, MI
Contact:

Re: Character Gender Select Problem/Question

#5 Post by Bryy »

I *really* do not want to have to do if/then for the start of every single scene. Well, I could BUT I also have five expressions for each gender version. I also wanted to do alt-outfits for each party member. Grrrrrr.

UPDATE:

I just changed it to:

Code: Select all

label chara_select:
    whc "Are you a girl or a boy?"
    menu:
        "Girl":
            $ girl = True
            $p1.image = "TEST_CHARA_2.png" #not done yet
            jump act1_start
        "Boy":
            $ boy = True
            $p1.image = "perry_male_shocked.png"
            jump act1_start
And the scene plays, but I get this:

Image

If I can just figure this one out, it would work, except I have multiple outfits and expressions that I would like to include as well. I guess I *could* give everything its own name, but that's pretty much a non-starter.

User avatar
NialGrenville
Regular
Posts: 184
Joined: Tue Aug 30, 2016 6:30 pm
Projects: PaS: The Awakening; The Heart Woods; The Witch and the Fairy
Organization: Gabe Works, Inc.
Contact:

Re: Character Gender Select Problem/Question

#6 Post by NialGrenville »

Well lets tackle this situation shall we?

Lets begin,

Code: Select all

    if girl:
        #PERRY, FEMALE
        image p1 = "TEST_CHARA_2.png" #not done yet
        image p2 = "perry_fem_sad.png"#not done yet
        image p3 = "perry_fem_hurt.png"#not done yet
        image p4 = "perry_fem_happy.png"#not done yet
        image p5 = "perry_fem_angry.png"#not done yet
        image pa1 = "perry_arfem_shocked.png"#not done yet
        image pa2 = "perry_arfem_sad.png"#not done yet
        image pa3 = "perry_arfem_hurt.png"#not done yet
        image pa4 = "perry_arfem_happy.png"#not done yet
        image pa5 = "perry_arfem_angry.png"#not done yet
    if boy:
        #PERRY, MALE
        image p1 = "perry_male_shocked.png"
        image p2 = "perry_male_sad.png"
        image p3 = "perry_male_hurt.png"
        image p4 = "perry_male_happy.png"
        image p5 = "perry_male_angry.png"
        image pa1 = "perry_armale_shocked.png"
        image pa2 = "perry_armale_sad.png"
        image pa3 = "perry_armale_hurt.png"
        image pa4 = "perry_armale_happy.png"
        image pa5 = "perry_armale_angry.png"
This is the big issue, if statements! A beginner of python! Some people forget this, even I do sometimes.
If's are to be followed either by a elif or else statement!
Change your second if to an else! Post your update here and we'll buff this out!

I also recommend placing them in an Init: block. Since they are dealing with images in different formats. To be honest, the easier solution, is just defining the characters and placing their "default" image in. Then define each image separately to use later (with different names of course).
*Me*, *You, ***Calamazoo: *Singularity-A.I.*: *Proceed to processing
PaS: The Awakening, current status: 42%
The HeartWoods, current status: 0%
The Wonderful Mell! My PFI creator Honest Critique

User avatar
valeatory
Regular
Posts: 36
Joined: Mon Apr 23, 2007 3:01 pm
Projects: Nightglove Institute, Monstrata Fracture
Organization: Astralore Games
Tumblr: valeatory
itch: astralore
Location: America
Contact:

Re: Character Gender Select Problem/Question

#7 Post by valeatory »

While I don't know anything about the method you tried the second time, I can tell you what's happening with your first attempt to set the images. `image` statements are always run before the game starts, so whichever one is furthest down in the file, no matter what, is the one that will stick - That's why in your case, the later male images are used, regardless of the variables' state.

I would try using DynamicImages, like this:

Code: Select all

image char smile = DynamicImage("[gender]_smile.png")
image char vsad = DynamicImage("[gender]_vsad.png")

default gender = "girl"

label start:
    show char smile
    "smiling girl"
    $ gender = "boy"
    "smiling boy"
    show char vsad
    "very sad boy"
Nightglove Institute - Kidnapped students, forced to train to be secret agents and assassins!
Monstrata Fracture - Date cute monsters! But will you risk destabilizing the human plane of existence?

User avatar
Bryy
Veteran
Posts: 407
Joined: Thu Dec 20, 2012 10:12 pm
Completed: 30+ games so far
Projects: Furry Shakespeare
Organization: Stegalosaurus Game Development
Location: Portage, MI
Contact:

Re: Character Gender Select Problem/Question

#8 Post by Bryy »

valeatory wrote:While I don't know anything about the method you tried the second time, I can tell you what's happening with your first attempt to set the images. `image` statements are always run before the game starts, so whichever one is furthest down in the file, no matter what, is the one that will stick - That's why in your case, the later male images are used, regardless of the variables' state.

I would try using DynamicImages, like this:

Code: Select all

image char smile = DynamicImage("[gender]_smile.png")
image char vsad = DynamicImage("[gender]_vsad.png")

default gender = "girl"

label start:
    show char smile
    "smiling girl"
    $ gender = "boy"
    "smiling boy"
    show char vsad
    "very sad boy"
Oh, thanks. I'll try it.

Code: Select all

    if girl:
        image p1 = "TEST_CHARA_2.png" #not done yet
    elif:
        image p2 = "perry_fem_sad.png"#not done yet
    elif:
        image p3 = "perry_fem_hurt.png"#not done yet
    elif:
        image p4 = "perry_fem_happy.png"#not done yet
    elif:
        image p5 = "perry_fem_angry.png"#not done yet
    elif:
        image pa1 = "perry_arfem_shocked.png"#not done yet
    elif:
        image pa2 = "perry_arfem_sad.png"#not done yet
    elif:
        image pa3 = "perry_arfem_hurt.png"#not done yet
    elif:
        image pa4 = "perry_arfem_happy.png"#not done yet
    elif:
        image pa5 = "perry_arfem_angry.png"#not done yet
    else:
        image p1 = "perry_male_shocked.png"
    elif:
        image p2 = "perry_male_sad.png"
    elif:
        image p3 = "perry_male_hurt.png"
    elif:
        image p4 = "perry_male_happy.png"
    elif:
        image p5 = "perry_male_angry.png"
    elif:
        image pa1 = "perry_armale_shocked.png"
    elif:
        image pa2 = "perry_armale_sad.png"
    elif:
        image pa3 = "perry_armale_hurt.png"
    elif:
        image pa4 = "perry_armale_happy.png"
    elif:
        image pa5 = "perry_armale_angry.png"
    show p1 at left with dissolve
    p "This is so weird."
    jump start
Probably not what you mean at all, but like this?
I also recommend placing them in an Init: block. Since they are dealing with images in different formats. To be honest, the easier solution, is just defining the characters and placing their "default" image in. Then define each image separately to use later (with different names of course).
I would if I was dealing with just one character image, and especially if I was not trying to do alt outfits as well (for every party member).

User avatar
NialGrenville
Regular
Posts: 184
Joined: Tue Aug 30, 2016 6:30 pm
Projects: PaS: The Awakening; The Heart Woods; The Witch and the Fairy
Organization: Gabe Works, Inc.
Contact:

Re: Character Gender Select Problem/Question

#9 Post by NialGrenville »

No, just place your if statement. Write your image list like before.
Then change your second if, to else:

Try this!:

Code: Select all

label chara_select:
    whc "Are you a girl or a boy?"
    menu:
        "Girl":
            $ girl = True
            $ boy = False
            jump start_2
        "Boy":
            $ boy = True
            $ girl = False
            jump start_2
label start_2:
    if girl:
        #PERRY, FEMALE
        image p1 = "TEST_CHARA_2.png" #not done yet
        image p2 = "perry_fem_sad.png"#not done yet
        image p3 = "perry_fem_hurt.png"#not done yet
        image p4 = "perry_fem_happy.png"#not done yet
        image p5 = "perry_fem_angry.png"#not done yet
        image pa1 = "perry_arfem_shocked.png"#not done yet
        image pa2 = "perry_arfem_sad.png"#not done yet
        image pa3 = "perry_arfem_hurt.png"#not done yet
        image pa4 = "perry_arfem_happy.png"#not done yet
        image pa5 = "perry_arfem_angry.png"#not done yet
    else:
        #PERRY, MALE
        image p1 = "perry_male_shocked.png"
        image p2 = "perry_male_sad.png"
        image p3 = "perry_male_hurt.png"
        image p4 = "perry_male_happy.png"
        image p5 = "perry_male_angry.png"
        image pa1 = "perry_armale_shocked.png"
        image pa2 = "perry_armale_sad.png"
        image pa3 = "perry_armale_hurt.png"
        image pa4 = "perry_armale_happy.png"
        image pa5 = "perry_armale_angry.png"
    show p1 at left with dissolve
    p "This is so weird."
    jump start
ctrl C and ctrl V that. Then test it!
If it works, we can Iron out picture definitions afterward.
*Me*, *You, ***Calamazoo: *Singularity-A.I.*: *Proceed to processing
PaS: The Awakening, current status: 42%
The HeartWoods, current status: 0%
The Wonderful Mell! My PFI creator Honest Critique

User avatar
Bryy
Veteran
Posts: 407
Joined: Thu Dec 20, 2012 10:12 pm
Completed: 30+ games so far
Projects: Furry Shakespeare
Organization: Stegalosaurus Game Development
Location: Portage, MI
Contact:

Re: Character Gender Select Problem/Question

#10 Post by Bryy »

valeatory wrote:While I don't know anything about the method you tried the second time, I can tell you what's happening with your first attempt to set the images. `image` statements are always run before the game starts, so whichever one is furthest down in the file, no matter what, is the one that will stick - That's why in your case, the later male images are used, regardless of the variables' state.

I would try using DynamicImages, like this:

Code: Select all

image char smile = DynamicImage("[gender]_smile.png")
image char vsad = DynamicImage("[gender]_vsad.png")

default gender = "girl"

label start:
    show char smile
    "smiling girl"
    $ gender = "boy"
    "smiling boy"
    show char vsad
    "very sad boy"
Question.

Why would I still need to make two character files?
NialGrenville wrote:No, just place your if statement. Write your image list like before.
Then change your second if, to else:

Try this!:

Code: Select all

label chara_select:
    whc "Are you a girl or a boy?"
    menu:
        "Girl":
            $ girl = True
            $ boy = False
            jump start_2
        "Boy":
            $ boy = True
            $ girl = False
            jump start_2
label start_2:
    if girl:
        #PERRY, FEMALE
        image p1 = "TEST_CHARA_2.png" #not done yet
        image p2 = "perry_fem_sad.png"#not done yet
        image p3 = "perry_fem_hurt.png"#not done yet
        image p4 = "perry_fem_happy.png"#not done yet
        image p5 = "perry_fem_angry.png"#not done yet
        image pa1 = "perry_arfem_shocked.png"#not done yet
        image pa2 = "perry_arfem_sad.png"#not done yet
        image pa3 = "perry_arfem_hurt.png"#not done yet
        image pa4 = "perry_arfem_happy.png"#not done yet
        image pa5 = "perry_arfem_angry.png"#not done yet
    else:
        #PERRY, MALE
        image p1 = "perry_male_shocked.png"
        image p2 = "perry_male_sad.png"
        image p3 = "perry_male_hurt.png"
        image p4 = "perry_male_happy.png"
        image p5 = "perry_male_angry.png"
        image pa1 = "perry_armale_shocked.png"
        image pa2 = "perry_armale_sad.png"
        image pa3 = "perry_armale_hurt.png"
        image pa4 = "perry_armale_happy.png"
        image pa5 = "perry_armale_angry.png"
    show p1 at left with dissolve
    p "This is so weird."
    jump start
ctrl C and ctrl V that. Then test it!
If it works, we can Iron out picture definitions afterward.
Nope.

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: Character Gender Select Problem/Question

#11 Post by namastaii »

I was saying to put the if/else statement in a live composite. If you don't know what that is, it's pretty easy to google, just include ren'py in the search. The live composite will show certain images as layers to create your sprite as a whole but you seem to have just one flat image for an entire sprite with an expression which is fine too. You could just make a composite (idk if it's the best for one layer) of your one sprite and have it set up to where the image changes depending on a variable - something like "myimage_%d.png"%(expression)
This basically takes the variable called expression and changes the %d of the filename part to whatever the variables value is. Does that make sense? Then you have an if/else statement in your composite to determine which file will be shown. the boy one or the girl one. And I will go ahead and try to make a simple example that works for you if you still haven't found a decent way that works. I've just been a little busy today sorry! My way might be more complicated than it needs to because I'm used to live composites and dealing with layers and variables because I need to do it a more complicated way but I'll keep it as simple as possible while doing a way I'm familiar with that I KNOW works. and should be fairly easy to understand/learn.

Those these guys are right. If/elif/else is important. That's why I mentioned just trying the else but I think you said that didn't work. Also, it could be true that using 'image' in a label might not work too well. This is not a very good way to go about things. So we'll get this sorted out as smoothly as possible.

If you use a live composite (like I'm going to show you) then you can just change a variable (for the expression of your sprite) to change if your sprite is sad or happy etc. You wouldn't have to hide a happy sprite then show a sad sprite. It would be an instant change with a $ my_expression = 2 for sad etc

User avatar
valeatory
Regular
Posts: 36
Joined: Mon Apr 23, 2007 3:01 pm
Projects: Nightglove Institute, Monstrata Fracture
Organization: Astralore Games
Tumblr: valeatory
itch: astralore
Location: America
Contact:

Re: Character Gender Select Problem/Question

#12 Post by valeatory »

Bryy wrote: Why would I still need to make two character files?
I'm not sure entirely what you mean by that. Do you mean that you need an image for a girl and an image for a boy? Or something else? It seems to me like you already have two sets (one for each gender) of many more than two images each. If you wanted to use DynamicImages in the code you had already posted, it might look something like this:

Code: Select all

default gender = "fem" #or "male", if you prefer
image p1 = "perry_[gender]_shocked.png"
image p2 = "perry_[gender]_sad.png"
image p3 = "perry_[gender]_hurt.png"
image p4 = "perry_[gender]_happy.png"
image p5 = "perry_[gender]_angry.png"
image pa1 = "perry_ar[gender]_shocked.png"
image pa2 = "perry_ar[gender]_sad.png"
image pa3 = "perry_ar[gender]_hurt.png"
image pa4 = "perry_ar[gender]_happy.png"
image pa5 = "perry_ar[gender]_angry.png"

label chara_select:
    whc "Are you a girl or a boy?"
    menu:
        "Girl":
            $ gender = "fem"
            jump start_2
        "Boy":
            $ gender = "male"
            jump start_2
label start_2:
    show p1 at left with dissolve
    p "This is so weird." #should have the image of the correct gender
    jump start
You would need to rename your test image to fit your later pattern of "perry_fem_shocked.png", and I am not sure if using so many DynamicImages would be less efficient than another solution (Like LiveComposite, which it seems others know more about), but it should work and make for readable code.
I would also recommend renaming your image variables, though, to something more descriptive, like `perry shocked` instead of `p1`, for the sake of your ease of writing later.
Nightglove Institute - Kidnapped students, forced to train to be secret agents and assassins!
Monstrata Fracture - Date cute monsters! But will you risk destabilizing the human plane of existence?

User avatar
Bryy
Veteran
Posts: 407
Joined: Thu Dec 20, 2012 10:12 pm
Completed: 30+ games so far
Projects: Furry Shakespeare
Organization: Stegalosaurus Game Development
Location: Portage, MI
Contact:

Re: Character Gender Select Problem/Question

#13 Post by Bryy »

So basically:

Code: Select all

default gender = "fem"
image p1 = "perry_[gender]_shocked.png"
image p2 = "perry_[gender]_sad.png"
image p3 = "perry_[gender]_hurt.png"
image p4 = "perry_[gender]_happy.png"
image p5 = "perry_[gender]_angry.png"
image pa1 = "perry_ar[gender]_shocked.png"
image pa2 = "perry_ar[gender]_sad.png"
image pa3 = "perry_ar[gender]_hurt.png"
image pa4 = "perry_ar[gender]_happy.png"
image pa5 = "perry_ar[gender]_angry.png"

#then the same thing but with male in gender
gender = "male"
image p1 = "perry_[gender]_shocked.png"
image p2 = "perry_[gender]_sad.png"
image p3 = "perry_[gender]_hurt.png"
image p4 = "perry_[gender]_happy.png"
image p5 = "perry_[gender]_angry.png"
image pa1 = "perry_ar[gender]_shocked.png"
image pa2 = "perry_ar[gender]_sad.png"
image pa3 = "perry_ar[gender]_hurt.png"
image pa4 = "perry_ar[gender]_happy.png"
image pa5 = "perry_ar[gender]_angry.png"

label chara_select:
    whc "Are you a girl or a boy?"
    menu:
        "Girl":
            $ gender = "fem"
            jump start_2
        "Boy":
            $ gender = "male"
            jump start_2
label start_2:
    show p1 at left with dissolve
    p "This is so weird." #should have the image of the correct gender
    jump start
Is this closer to it?

User avatar
valeatory
Regular
Posts: 36
Joined: Mon Apr 23, 2007 3:01 pm
Projects: Nightglove Institute, Monstrata Fracture
Organization: Astralore Games
Tumblr: valeatory
itch: astralore
Location: America
Contact:

Re: Character Gender Select Problem/Question

#14 Post by valeatory »

That's closer, but you don't actually need to define the images twice. If you look at the lines you're putting in after `gender="male"`, they're the same as the ones before it. All of those (as well as the `gender="male"` line) are not necessary, since the images will automatically update when you change gender later in the menu.
Basically, just try the code I posted and see how it goes.
Nightglove Institute - Kidnapped students, forced to train to be secret agents and assassins!
Monstrata Fracture - Date cute monsters! But will you risk destabilizing the human plane of existence?

User avatar
Bryy
Veteran
Posts: 407
Joined: Thu Dec 20, 2012 10:12 pm
Completed: 30+ games so far
Projects: Furry Shakespeare
Organization: Stegalosaurus Game Development
Location: Portage, MI
Contact:

Re: Character Gender Select Problem/Question

#15 Post by Bryy »

Sure, thing; so it will search for male in the images folder if fem is set to False?

Also where do I put the default = fem code? I assume in the initial int bracket.

Post Reply

Who is online

Users browsing this forum: No registered users