Question on redefining functions in renpy's python modules (e.g. exports.py)

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
srksrk 68
Regular
Posts: 30
Joined: Fri Jul 19, 2019 8:10 pm
Contact:

Question on redefining functions in renpy's python modules (e.g. exports.py)

#1 Post by srksrk 68 »

Hello,

since I am relatively new to python/renpy I am wondering if it is safe to modify or redefine coding in the python modules that come with renpy. For example, I want to have a custom say function which is originally defined in exports.py:

Code: Select all

init 100 python:
    def my_say(who, what, *args, **kwargs):
        """
        Copied from exports.py
        """
        
        <some custom coding here>
        
        if renpy.config.old_substitutions:
            # Interpolate variables.
            what = what % renpy.exports.tag_quoting_dict

        if who is None:
            who = renpy.store.narrator  # E1101 @UndefinedVariable

        if renpy.config.say_arguments_callback:
            args, kwargs = renpy.config.say_arguments_callback(who, *args, **kwargs)

        if isinstance(who, (str, unicode)):
            renpy.store.say(who, what, *args, **kwargs)
        else:
            who(what, *args, **kwargs)
    
    renpy.exports.say = my_say
This seems to work quite well. However, I am not very comfortable in doing it like this, maybe this coding is subject to incompatible changes in later releases. Also, if the original say function is being modified later, I will lose all those changes.

Is there a better way to do stuff like this? Is it even recommended?

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot]