Setting a Random Variable with Input from another Random Variable

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
verysunshine
Veteran
Posts: 339
Joined: Wed Sep 24, 2014 5:03 pm
Organization: Wild Rose Interactive
Contact:

Setting a Random Variable with Input from another Random Variable

#1 Post by verysunshine »

I want to have a character's name set with input based on gender, another randomly generated variable. Currently, the "gender" variable sets and the code will run, but the game will not use gender to assign a name.

Code: Select all

    class GENERATOR:
        def genderpickerroll(self):
            genderpick = renpy.random.choice(genderpicker)
            store.gender = genderpick + ""
            
        def namegeneration(self):    
            if gender == "M":    
            
            
                name = renpy.random.choice(male_name_list)
                surname = renpy.random.choice(surname_list)
                store.name = name + " " + surname
                
            if gender == "F":
            
                name = renpy.random.choice(female_name_list)
                surname = renpy.random.choice(surname_list)
                store.name = name + " " + surname
                
            else:
                name = "Error"
                surname = renpy.random.choice(surname_list)
                store.name = babyname + " " + surname
As this isn't too important, I'm going to make a gender-neutral name list to have it draw from in the "else" case.

Why I'm not using if/else for the name choice code, when there are only two options: To test if the code works, for now. I might add other options later.

Why I'm repeating the store.name code: I don't want to break the code. If I could have it only once, that would be nice.

Update: With the gender-neutral names, I have found that it will now read the gender correctly if gender = F. If gender = M, no dice.

Build the basics first, then add all the fun bits.

Please check out my games on my itch.io page!

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2400
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Setting a Random Variable with Input from another Random Variable

#2 Post by Ocelot »

Check what happens if gender is "M":

First it checks if it equals to "M". It is True, so it sets name and associated vaiables to male name.
Then it checks if gender is "F". It is False, so execution goes to the associated else block and sets name to Error

You need to make second if into elif.
< < insert Rick Cook quote here > >

verysunshine
Veteran
Posts: 339
Joined: Wed Sep 24, 2014 5:03 pm
Organization: Wild Rose Interactive
Contact:

Re: Setting a Random Variable with Input from another Random Variable

#3 Post by verysunshine »

Ocelot wrote: Tue Jan 16, 2018 2:15 pm Check what happens if gender is "M":

First it checks if it equals to "M". It is True, so it sets name and associated vaiables to male name.
Then it checks if gender is "F". It is False, so execution goes to the associated else block and sets name to Error

You need to make second if into elif.
That would be it. Thank you.

Build the basics first, then add all the fun bits.

Please check out my games on my itch.io page!

Post Reply

Who is online

Users browsing this forum: Google [Bot]