Dumbass Renpy question, in changing all instances of a class.

May 13, 2023
35
31
Okay, htis is probably gonna be simple and I'll kick myself, but right now for my fertile blessing game, I am creating classes:
class Person():

def __init__(self, character, name, boobsize = 0, sluttiness = 0, obedience = 0, infected = 0, location = 0, affection = 0):
self.c = character
self.name = name
self.boobsize = boobsize
self.sluttiness = sluttiness
self.obedience = obedience
self.infected = infected
self.affection = affection
self.location = location


Now it's working, but what I want, and I'm not certain how to do it is to set up a test at teh beginning of every day. Where if "infection == 1" (or any number over one, since the game will ultimately hae different infection levels), the other stats change.
Okay, good. But I've been searching for a way to make the test global, going through every case, IE, if you have Stacy, wilma, and Eunice, and test them, before applying the change, but I don't want to write a ton of code that checks out every name specifically.

I want a code that will check:
if infection == 1
then (do stuff to the rest of the states)

and do it for every character automatically, so that even if I add sheila later in the game, I don't have to specifically add her to the test routine.

So yeah, I'm pretty certain someone's going to hit me with the dumb stick, but my searches involving wildcards and renpy have come up blank and some of my more normal sources (reddit) are currently not available.
 

BuddyBoi76

Newbie
May 14, 2021
55
295
Creating a global list of all your characters and iterating through it seems like the simplest solution. You can add in new characters to the list without breaking anything.

So something like

char_list=[Stacy, Wilma, Eunice]

for char in char_list:
do infection_check(char)

And later on you can just do char_list.append(Alex) without changing your daily infection checker.

This is using python lists though. There might be an easier way to do this using some built-in RenPy stuff I don't know about, but this is what comes to mind. Hope it helps until someone posts a better solution.
 

Deleted member 2282952

Developing I SCREAM
Game Developer
May 1, 2020
416
870
For more complicated stuff you can do
char_list={
char_1:{
parameter1: "",
parameter2: "",
}
char_2:{
parameter1: "",
parameter2: "",
}
}

And then easily access by char_list["char_1"]["parameter1"]
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,957
16,192
Now it's working, but what I want, and I'm not certain how to do it is to set up a test at teh beginning of every day. Where if "infection == 1" (or any number over one, since the game will ultimately hae different infection levels), the other stats change.
Python:
init python:
    class Person( renpy.python.RevertableObject ):
        [...]

        def dailyCheck( self ):
            if store.infection == 1:
                self.infected +=1
                [...]

default Stacy = Person( [...] )
default Wilma = Person( [...] )

label whatever:
    python:
        for p in [ Stacy, Wilma, [...] ]:
            p.dailyCheck()

For more complicated stuff you can do
char_list={
char_1:{
parameter1: "",
parameter2: "",
}
char_2:{
parameter1: "",
parameter2: "",
}
}

And then easily access by char_list["char_1"]["parameter1"]
Here she would hit a wall.

"char_list" should stay not savable, in order to be easily updated when needed, therefore it should be created with define. This while "char_1", "char_2", etc. should be saved, since they are part of the game state, therefore they must be created with default.
But default being proceeded after define, it can't happen.

It's better to do what I shown above, and have the whole process being part of the class. Like only the values are saved, the "dailyCheck" method will always be up to date, and can more easily proceed all the possibilities.
If really "parameter1" and "parameter2" are different from a character to another, then just have them defined in __init__.
 
  • Like
Reactions: osanaiko