possibly grouping sprites based on weight?

im trying to make a mechanic where based on the relationship points the sprites have 4 “stages” with the same expressions as the default ones, and I’ve assigned points to choices and all that but now every-time i put in a sprite i have to write an if/then statement to update the sprite based on the points. its basically

if connie_relationship >= 1:
    show connie normal m at right
else:
    show connie normal s at right
c"hi"
if connie_relationship >= 1:
    show connie shy m
else:
    show connie shy s

every single time i change expressions and for every character! is there a way to shorten this or am i doomed to have to do this until the end of time?

edit: im using renpy btw!

1 Like

You want to get the value then display the image which can be done without added if statements.

Most authors will code some sort of class system.

I typed this up and decided it was lame and annoying to explain so instead…

You would do something like this:

 if connie_relationship >= 1:
       $ connie.mood = "normal"
 else:
       $ connie.mood = "shy"

then elsewhere in the code when needed run.

      $connie_path = str("/images/Sprites/connie/" + connie.mood + ".png")

then when you need to show connie you would just use

   show connie at right

now uh, this might seem like just as much work… but what I’m trying to explain is that… you type the if once, in some sort of npc class setup file and then when needed you can just call the npc’s show function which will run the if and set the correct file for show… essentially you only have to type the if statement once, even if you need to use it 100s of times.

edit:

okay so here’s a rough attempt at creating some sort of connie class (although it might be better to define an npc class of which connie is just one of many).

class connie(object):
    def __init__(self, identity):
        self.mood = "shy"
        self.relationship = 0
        self.i = identity

    def image(self):
         if connie_relationship >= 1:
             $ connie.mood = "normal"
         else:
            $ connie.mood = "shy"
             return str("/images/Sprites/connie/" +connie.mood + ".png")

then when you want to show connie you could use

 $ connie_path = connie.image()
           show connie at right

So, the reason you need an if statement is NOT to display the image, you need the if statement to convert 0 into “shy” and 1 into “normal”

Although if the shy normal relationship is binary like that you could just use something like false/true or 0/1 and set the filenames to instead of using the words shy and normal just use false/true or 0/1 in the filename. So, yeah, you don’t actually need an if statement to choose the right file, but you do need an if statement to convert an integer into a word that’s a string.

another way to approach it I suppose would be this:

set up

label ShowConnie(int tempCR):
       if tempCR >= 1:
    show connie normal m at right
else:
    show connie normal s at right
c"hi"
if tempCR >= 1:
    show connie shy m
else:
    show connie shy s

then in the body of the game in an event you’d run

ShowConnie(connie_relationship)

This way you only have to type ShowConnie(connie_relationship) over and over in the body of the game and it handles the if nonsense once elsewhere.

edit: Sorry this explanation really sucks, doesn’t it. Hopefully it’s better than nothing, if someone else writes a better explanation I can always delete mine.

1 Like

thanks for the response im gonna work on this right now and run some tests with it too… it sounds like it should work though…

You can either end up with a folder that is like Connie1normal.png Connie1shy.png
Connie2normal.png Connie2shy.png Connie3normal.png Connie3shy.png

or you could do like Connie is a folder and 1/2/3/4 are each subfolders inside of which you have normal.png and shy.png

Then yeah, you only need to setup the if once, then simply refer to the if elsewhere, and you can use str(variableaboutweight)+str(variableaboutmood) to create the right file to call, which would let you combine weight stages and moods (my examples above are purely two moods).

You could do away with if statements entirely if you just say had a variable for size and a variable for mood you could then run something like.

$connie_path = str("/images/Sprites/connie/" + str(connie.stage) + connie.mood+ ".png")

show connie at right

Sidenote: I believe I made an error you only need to use str(variable) when the variable is something like an integer. str(5) is the same as “5”. So if you were to assign “shy” the string to a variable you wouldn’t need to make the string into a string again.

This sort of depends on if you want the shy mood to be “shy” in the code or if you’re fine just assuming you’ll remember that an integer value of 0 means shy and you can just name all your shy images as having a 0 in them, which case you’ll want to keep the str(variable) because it’ll be str(0) which will be “0” which will be valid as something you can add to a filename.

sidesidenote: I do think you can use str(“this is already a string”) anyways though to be redundant. And you might even have to if you’re adding together several strings like str(“this is already a string” + str(5) + str(0)+“this is also already a string”)

You could probably look at the code for growth academy to get inspiration maybe? I know that game has a ton of sprites and un-encrypted published source code in each release. I know my explanation barely made any sense.

Oh importantly: I am basing my answers off of an understanding of python, not ren’py, so there might be some sort of ren’py convention or editing tool that automates this or makes this process easier that I’m not personally aware of.

You might also wanna try showif statements

https://www.renpy.org/doc/html/screens.html

which are just something ren’py specific that do what you ask here.

Personally what I’d probably do is cut down on if’s by just using an integer for mood and an integer for weight size stage and then using a show command that included those two variables and naming all my png files with two numbers in them one for mood and one for weight. That’s inelegant and clunky though long term.