Ren'Py What's the best way to store a large collection of randomly generated characters?

Jun 11, 2020
59
130
I've listened to everyone's advice and switched to renpy for that game I'm making. And thus far I've made quite a bit more progress than I had with kivy in terms of just functionality. But now I need to know before I go much further, what should I use to store large numbers of randomly generated characters?
My characters (just male ones for now) are simply a class with objects and subclasses with more objects to describe everything about them. I've got the character generation down but now I need to store them all after they've been generated. I've been using dictionaries for that but feels somewhat convoluted with how dictionaries are in python with more than simple key value pairs. And renpy doesn't seem particularly friendly to it either with how many issues I've had in getting the dictionaries to even work. I've heard ren'py has a "store" function for this and I'm wondering what that is and whether I should or can use that. Can anyone who has experience with this sort of thing recommend something?
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,957
16,188
[...] what should I use to store large numbers of randomly generated characters?
It totally depend what you intend to do with them.


I've been using dictionaries for that but feels somewhat convoluted with how dictionaries are in python with more than simple key value pairs.
Why do you want more than simple key/value pairs, if each character is an object ? All you need is to pair the character object with the character name, or ID, in order to be able to address it when you need it.

Python:
init python:
    def generate( name ):
        maleChars[name] = AMaleCharacter()
        maleChars[name].whatever = [whatever randomization]
        maleChars[name].whatever = [whatever randomization]

default maleChars = {}

label starts:
    $ generate( "Alan" )
    $ generate( "Sam" )
    [...]

label whatever:
    [...]
    if maleChars["Alan"].strength < 2:
        "Alan isn't strong enough, he can't to that"
    [...]

And renpy doesn't seem particularly friendly to it either with how many issues I've had in getting the dictionaries to even work.
Ren'Py have absolutely no issue with . It is always directly handled by the Python interpreter itself ; either through code bloc execution, or through code evaluation.


I've heard ren'py has a "store" function for this and I'm wondering what that is and whether I should or can use that.
There's no "store" function, but there's a named "store" that serves as global context for the game variables.
And you are already using it ; "the default place that Ren'Py stores Python variables is called the store."


Can anyone who has experience with this sort of thing recommend something?
Giving a bit more attention to the documentation, starting by the links in this post.
 

DebatingPanda

Member
Game Developer
Mar 1, 2023
274
1,089
If you still need some help beside the good infos from anne O'nymous. I use this code in my novel for getting characters from a list. I add my Person class instance to a list and each instance has a Name where I can loop through.

Python:
init 0 python:
    class PersonHandler:
        def __init__(self):
            self._personList = []

        def addPerson(self, person):
            self._personList.append(person)

        def getPersonByName(self, personName):
            if(personName is None):
                pass

            for person in self._personList:
                if(person.Name == personName):
                    return person