Page 1 of 1
How Do I Go About Randomly Generating Different Characters?
Posted: Sun Nov 25, 2018 4:40 pm
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?
Re: How Do I Go About Randomly Generating Different Characters?
Posted: Mon Nov 26, 2018 9:43 am
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.
Re: How Do I Go About Randomly Generating Different Characters?
Posted: Mon Nov 26, 2018 4:12 pm
by thewritingperson1
Thank you Dannx! I will try this out.
Re: How Do I Go About Randomly Generating Different Characters?
Posted: Mon Nov 26, 2018 4:52 pm
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?