Hello, cuties! It’s Glimmer again. Today we talk about characters. “But didn’t we just talk about characters last week?” Yes, we did! But only in the high level sense. Today, what I really want to talk about is the internal implementation of characters, with a sprinkle of inheritance for good measure.
I won’t bore you too much with the specifics, but Ren’Py defines characters using the Python class ADVCharacter. It is abstracted from its Python-ness in the documentation, a normally great thing about Ren’Py that makes it very easy to use. (This will be important later…) The ADVCharacter class contains all kinds of information about characters in your game, including their name, text color, image tag (for identifying their character art), and more. If you want a deeper explanation, feel free to check out Ren’Py’s documentation.
The limitation with the class is that it does not contain many of the things needed for Cosmic Latte characters, such as affection level and cosmetics. No problem, right? Well… up until this point in development, I didn’t really understand the internal class structure. So, I had somewhat clumsily slapped an ADVCharacter object as an attribute (or member) of an entirely different class called RomanceCharacter.
This was… okay for a while, though it did require two different variables to refer to a “Cosmic Latte character” (RomanceChar) and a “Ren’Py character” (ADVCharacter). Annoying, but it can be dealt with. But with the recent rework of the voice system to make it a bit more “smart”, I ran into a problem where a passed reference to the ADVCharacter needed to refer back to the RomanceCharacter it is contained within. Oopsie!
But then I realized I can just set up the RomanceCharacter to inherit from the ADVCharacter class instead, and tack on any extra attributes and functions as an extension of that class. I suspect back when I first implemented it, I tried to inherit from a class called Character, but I failed to realize that was just a function to construct an ADVCharacter. Or maybe I’m just dumb, who knows. I have no idea why it took me so long to realize this, but it’s way more seamless this way. Now to fix tons of lines that refer to one type of object or the other… yeah. Still working on that part.
But hey! It was worth it. Now voice clips can be played automagically without having to specify the audio file every time. (Ren’Py does have a similar feature built in, but its unique identifier system does not quite suit our needs.) And now interacting with character objects is greatly simplified! Woo!
Anyways, that’s about all I have for today. Thanks for reading this article. Love you all!