How Do I Go About Randomly Generating Different Characters?
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.
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.
-
- Newbie
- Posts: 8
- Joined: Sat Nov 24, 2018 7:16 pm
- Contact:
How Do I Go About Randomly Generating Different Characters?
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?
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:
The screen is just so you can test out the code quickly.
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
-
- Newbie
- Posts: 8
- Joined: Sat Nov 24, 2018 7:16 pm
- Contact:
Re: How Do I Go About Randomly Generating Different Characters?
Thank you Dannx! I will try this out.
-
- Newbie
- Posts: 8
- Joined: Sat Nov 24, 2018 7:16 pm
- Contact:
Re: How Do I Go About Randomly Generating Different Characters?
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?
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot], Ocelot