Ren'Py Is it possible to create classes in renpy without complicating future development?

Pathologico

New Member
May 9, 2018
8
4
Hi!

I was creating a game in Renpy, for now I'm just creating the storyline in a linear way because I plan to add the gameplay later. I work as a programmer so I like to create classes and "systems" to manipulate things and that's what I wanted to do in renpy, create my own character classes, items, events in story development and others for the UI. But first I wanted to know if I have to be careful or if I have to take into account something in the case of future updates of the game if I publish a chapter version and if it can cause me problems if I want to generate the translation (for example if I create a localization class with the name = "farm" and I must translate that word to "ganja" in Spanish, I have to do something special to get it right)?

In summary the question is the one I put in the title, I want to know if it is feasible to do so and how it could affect the development in Renpy, my experience as a developer is not associated with Renpy so I do not know what could be the limitations.

And if you can tell me what could be the problems I should avoid that would be great!

Sorry if the question is too general or if I didn't explain well, anything you can ask me to clarify something.
 
  • Like
Reactions: Mock1ngb1rd

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,976
16,232
I work as a programmer [...]
Did they stopped to teach what a "doc" folder, like the one that come with Ren'Py SDK, is, and/or that a manual exist to be read ? Why not read the one on your computer, that is also available online ?


But first I wanted to know if I have to be careful or if I have to take into account something in the case of future updates of the game if I publish a chapter version
Well, isn't what the page of the manual cover ?


and if it can cause me problems if I want to generate the translation (for example if I create a localization class with the name = "farm" and I must translate that word to "ganja" in Spanish, I have to do something special to get it right)?
I'm pretty sure that the page of the manual answer this...


[...] I want to know if it is feasible to do so [...]
A quick look at this part of the forum, and/or to the code of some Ren'Py games that looks advanced, would have answered this question.


Here is a "class" I've made some time ago as idea, it's possible and works so far, but I'm not sure where the limits of ren'py are.
*sigh*

Having a variable named MC, what is also a class name... The fucking scope !

And, a list to host the character attributes ? Why not a dict or, since you're programmer, a blank class ?
/!\ wrote on the fly /!\
Python:
class Attributes( object ):
    def __init__( self ):
        self.__attributes = {}

    def create( self, name, value ):
        if name in self.__attributes: return # or raise an exception
        self.__attributes[name] = value

    def __getattr__( self, name ):
        if not name in self.__attributes: raise AttributeError( "'{}' object has no attribute '{}'".format( self.__class__.__name__, name ) )
        return self.__attributes[name]

    def __setattr__( self, name, value ):
        if name.endswith( '__attributes' ): return super( Attributes, self ).__setattr__( name, value )
        if not name in self.__attributes: raise AttributeError( "'{}' object has no attribute '{}'".format( self.__class__.__name__, name ) )
        self.__attribute[name] = value
Edit: obvious...
 
Last edited:

Mock1ngb1rd

Member
May 14, 2023
122
361
*sigh*

Having a variable named MC, what is also a class name... The fucking scope !

And, a list to host the character attributes ? Why not a dict or, since you're programmer, a blank class ?
I'm not a programmer and never said so. It was one of my first attempts at making classes.
 

Pathologico

New Member
May 9, 2018
8
4
Did they stopped to teach what a "doc" folder, like the one that come with Ren'Py SDK, is, and/or that a manual exist to be read ? Why not read the one on your computer, that is also available online ?




Well, isn't what the page of the manual cover ?




I'm pretty sure that the page of the manual answer this...




A quick look at this part of the forum, and/or to the code of some Ren'Py games that looks advanced, would have answered this question.




*sigh*

Having a variable named MC, what is also a class name... The fucking scope !

And, a list to host the character attributes ? Why not a dict or, since you're programmer, a blank class ?
/!\ wrote on the fly /!\
Python:
class Attributes( object ):
    def __init__( self ):
        self.__attributes = {}

    def create( self, name, value ):
        if name in self.__attributes: return # or raise an exception
        self.__attributes[name] = value

    def __getattr__( self, name ):
        if not name in self.__attributes: raise AttributeError( "'{}' object has no attribute '{}'".format( self.__class__.__name__, name ) )
        return self.__attributes[name]

    def __setattr__( self, name, value ):
        if name.endswith( '__attributes' ): return super( Attributes, self ).__setattr__( name, value )
        if not name in self.__attributes: raise AttributeError( "'{}' object has no attribute '{}'".format( self.__class__.__name__, name ) )
        self.__attribute[name] = value
Edit: obvious...
I ask so that someone with experience can give me what problems I may have or think about before solving a problem.

But if this kind of question is not valid in the forum you could say it directly, I had never posted here, I thought it was to create a conversation on how to deal with the development of classes in renpy. Suggesting to read the documentation is the opposite, it is to close the discussion and point out the obvious (that documentation exists).
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,976
16,232
Suggesting to read the documentation is the opposite, it is to close the discussion and point out the obvious (that documentation exists).
And what do you expect exactly ? That someone will summarize for you everything that is already in the documentation ?

As I said, the manual cover your questions, answering them all and this without real lack of information. So read it, and then if there's something you're not sure about, or you don't understand, ask about it. But expecting that people will do more efforts to answer you, what I already did by pointing directly to the right pages, than yourself did, it rarely works.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,976
16,232
I didn't even realize it would be a problem, sorry for hijacking the thread. :D
Don't worry, by itself it wasn't a problem. It's my brain that need some holidays and jumped a bit too quickly to conclusion.


I will have to hire someone for that part anyway, it just helps to know where the limits are while planning.
You don't necessarily need to hire someone. The code by itself isn't too bad. There's way worse, and you tried to keep it simple, what also is relatively rare. The issue is more the lack of... hmm, "practical knowledge".
Like by example for your list of objects for the attributes. I perfectly see from where it come, and yes at first intent it looks like the simplest way to do it. But then you have to effectively use it, to test a value, or to increase/decrease one. And then you discover that you have to browse all the list in search for the right attribute... It's not as easy as it looked at first.
A dictionary, like by example default MCAttributes = { "strength": 1, "lust": 0 } would serve the same purpose (grouping all the attributes in one place), will offering an easier access to the said attributes. Therefore it will reveal itself as even simpler.

But all this is something that can be relatively easily learned. You would have figured it by yourself after few times working with your code.
Practice, and ask when you're stuck or when you aren't sure if it's effectively the best approach, and you could probably do all the code by yourself.
 
  • Like
Reactions: Mock1ngb1rd

Mock1ngb1rd

Member
May 14, 2023
122
361
Don't worry, by itself it wasn't a problem. It's my brain that need some holidays and jumped a bit too quickly to conclusion.




You don't necessarily need to hire someone. The code by itself isn't too bad. There's way worse, and you tried to keep it simple, what also is relatively rare. The issue is more the lack of... hmm, "practical knowledge".
Like by example for your list of objects for the attributes. I perfectly see from where it come, and yes at first intent it looks like the simplest way to do it. But then you have to effectively use it, to test a value, or to increase/decrease one. And then you discover that you have to browse all the list in search for the right attribute... It's not as easy as it looked at first.
A dictionary, like by example default MCAttributes = { "strength": 1, "lust": 0 } would serve the same purpose (grouping all the attributes in one place), will offering an easier access to the said attributes. Therefore it will reveal itself as even simpler.

But all this is something that can be relatively easily learned. You would have figured it by yourself after few times working with your code.
Practice, and ask when you're stuck or when you aren't sure if it's effectively the best approach, and you could probably do all the code by yourself.
You don't have permission to view the spoiler content. Log in or register now.
 
Last edited:

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,611
2,258
[...] so I like to create classes and "systems" to manipulate things

I'm hardly an expert on python classes.
One bit of advice is to to base any new classes you create on RevertableObject.
Though according to , if you create a class within a .rpy script (as opposed to a .py file), it will automatically be assigned the correct object type. Stuff like ReverableList rather than List, etc.
RevertableObject (and the variations on it) all respect the mechanics of RenPy's rollback system.

I have some vague recollection that classes need to be be "pickleable" (pickle somehow being related to the save files and maybe the rollback log). Which would be way more helpful if I knew what pickling involved.

[...] if it can cause me problems if I want to generate the translation

Translation is done just before text is displayed and something RenPy already handles for you.
The RenPy developer kit launcher has a translate function that scans for displayable text within your game and has a replacement system for swapping one language for another.
The exception is the parts of a RenPy script that base Translation system normally ignores (usually code or custom functions). Even in those cases, if you prefix text with _( and suffix it with ) (overall _(), the translation system will include that text within the localized translation. Since any custom data stored within a class needs to be assigned somewhere within your script, _() should fill in the gaps in the displayable text your game that isn't already included by the translation processes.

In summary the question is the one I put in the title, I want to know if it is feasible to do so and how it could affect the development in Renpy, my experience as a developer is not associated with Renpy so I do not know what could be the limitations.

Revertable... and Pickleable are the important bits. But are largely already taken care of within RenPy without any further planning by yourself.

Honestly, searching here on F95 for "RevertableObject" is probably the best source of information on classes as you are thinking... albeit by association rather than deliberately (someone asks a question, and the answer is RevertableObject). And that answer will almost always be coming from anne O'nymous.

And if you can tell me what could be the problems I should avoid that would be great!

My general suggestion when someone starts a new game is to write a bad game that nobody will see before starting your "real" game. We tend to see a lot of "I want to write a game" posts... and rarely does anything ever come from those. We help, but ultimately those people like the idea of a game, but not the practicalities. Much better (from those of us who try to answer questions) are those people who have tried something, but failed - because we're helping refine rather than starting from scratch.

You're worst case scenario of getting it wrong is to have to post something like "Save files from version 0.6 and earlier will not work with 0.7". It won't stop development of your game, at worst some of your most devoted fans will need to play the game from the start again. F95 users are already familiar when developers needed to do this sort of thing.
(and if you do that, alter the line define config.save_directory = "{filepath}" within the options.rpy file a little - so previous save files are not listed).
 

Pathologico

New Member
May 9, 2018
8
4
I'm hardly an expert on python classes.
One bit of advice is to to base any new classes you create on RevertableObject.
Though according to , if you create a class within a .rpy script (as opposed to a .py file), it will automatically be assigned the correct object type. Stuff like ReverableList rather than List, etc.
RevertableObject (and the variations on it) all respect the mechanics of RenPy's rollback system.

I have some vague recollection that classes need to be be "pickleable" (pickle somehow being related to the save files and maybe the rollback log). Which would be way more helpful if I knew what pickling involved.




Translation is done just before text is displayed and something RenPy already handles for you.
The RenPy developer kit launcher has a translate function that scans for displayable text within your game and has a replacement system for swapping one language for another.
The exception is the parts of a RenPy script that base Translation system normally ignores (usually code or custom functions). Even in those cases, if you prefix text with _( and suffix it with ) (overall _(), the translation system will include that text within the localized translation. Since any custom data stored within a class needs to be assigned somewhere within your script, _() should fill in the gaps in the displayable text your game that isn't already included by the translation processes.




Revertable... and Pickleable are the important bits. But are largely already taken care of within RenPy without any further planning by yourself.

Honestly, searching here on F95 for "RevertableObject" is probably the best source of information on classes as you are thinking... albeit by association rather than deliberately (someone asks a question, and the answer is RevertableObject). And that answer will almost always be coming from anne O'nymous.




My general suggestion when someone starts a new game is to write a bad game that nobody will see before starting your "real" game. We tend to see a lot of "I want to write a game" posts... and rarely does anything ever come from those. We help, but ultimately those people like the idea of a game, but not the practicalities. Much better (from those of us who try to answer questions) are those people who have tried something, but failed - because we're helping refine rather than starting from scratch.

You're worst case scenario of getting it wrong is to have to post something like "Save files from version 0.6 and earlier will not work with 0.7". It won't stop development of your game, at worst some of your most devoted fans will need to play the game from the start again. F95 users are already familiar when developers needed to do this sort of thing.
(and if you do that, alter the line define config.save_directory = "{filepath}" within the options.rpy file a little - so previous save files are not listed).

Thanks! I had in mind to create several classes in python and I had not thought about how I could change the development according to the file. I had some things in python that I was thinking of moving to renpy but now I'm going to consider moving it to rpy if there is no incompatibility.