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.
I added python class "Test2" in "Test2.py" and defined it through "default" in "script.rpy". If I use rollback "Test2.nValue" behaves strange. In first position ("rollback 3") for "Test2" it equal 10 not 0. If I use "addValue" with rollback ("rollback 1") call this function change "Test2.nValue". Please tell me where is my mistake?
Python defined in .rpy files is transformed to allow rollback to work. Python imported from .py files is not. As a result, objects created in Python will not work with rollback, and probably should not be changed after creation.
Thank you for the answer. If I'll disable rollback "define config.rollback enabled = False" can I use changeable python's classes wich defined in the *.py files? Will this cause others problems? As I tested, "new game", "save" and "load" work normally.
Maybe I'm wrong. Have I no reason to use "* .py" files instead of "*.rpy" files?
BukaP wrote: ↑Sun Aug 01, 2021 3:26 pm
Thank you for the answer. If I'll disable rollback "define config.rollback enabled = False" can I use changeable python's classes wich defined in the *.py files? Will this cause others problems? As I tested, "new game", "save" and "load" work normally.
Maybe I'm wrong. Have I no reason to use "* .py" files instead of "*.rpy" files?
Loading uses rollback internally to return to the beginning of current statement, which might cause problems if player decides to save at wrong moment.
Generally you do not need to use .py files for game-related code. You can just can write it in separate rpy file and have it autoload. Alternatively: embrace functional programming and write immutable classes. External .py files are fine when you do not change instances of classes defined there.