How Do I Go About Randomly Generating Different Characters?

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
thewritingperson1
Newbie
Posts: 8
Joined: Sat Nov 24, 2018 7:16 pm
Contact:

How Do I Go About Randomly Generating Different Characters?

#1 Post by thewritingperson1 »

I am currently working on a random life sim and I am confused on how to go about making the game not only generate many characters (I will only start with 5 before I get crazy, but will increase it as time goes on), but make them all automatically have stored variables. How do I code in something to do this?

DannX
Regular
Posts: 99
Joined: Mon Mar 12, 2018 11:15 am
Contact:

Re: How Do I Go About Randomly Generating Different Characters?

#2 Post by DannX »

My take on this is to use a list, as in a python list. You would need some kind of function to generate new characters, I'll guess you want each of them to have their own characteristics, so objects are probably a good idea. Something like this:

Code: Select all

default m_names = ["Alan", "Bruce", "Carlos", "Dennis", "Ernest"]
default f_names = ["Alice", "Betty", "Caroline", "Deborah", "Eileen"]

default random_characters = []

init python:

    class Person(object):

        def __init__(self, name, gender, age):

            self.name = name
            self.gender = gender
            self.age = age

    def generate_character():
        global m_names, f_names, random_characters

        gen = renpy.random.choice(["male", "female"])

        if gen == "male":

            nam = renpy.random.choice(m_names)

        else:

            nam = renpy.random.choice(f_names)

        ag = renpy.random.randint(18,35)

        random_characters.append(Person(name=nam, gender=gen, age=ag))

screen character_generator():

    textbutton "Create Character!":
        xalign .5
        action Function(generate_character)

    vbox:
        xalign .5
        yalign .5
        for c in random_characters:
            text "{}, {}, {} years old".format(c.name, c.gender, c.age)

label start:

    scene black

    call screen character_generator
The screen is just so you can test out the code quickly.

thewritingperson1
Newbie
Posts: 8
Joined: Sat Nov 24, 2018 7:16 pm
Contact:

Re: How Do I Go About Randomly Generating Different Characters?

#3 Post by thewritingperson1 »

Thank you Dannx! I will try this out.

thewritingperson1
Newbie
Posts: 8
Joined: Sat Nov 24, 2018 7:16 pm
Contact:

Re: How Do I Go About Randomly Generating Different Characters?

#4 Post by thewritingperson1 »

It works! So know I only need to find out how to make variables for the generated character after I finish generating them. Like "love_points_to_mc" and "healthpoints". How do I make sure the game can keep tract of the variables for each different character?

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot], Ocelot