[SOLVED]Does renpy rollback support vars() ?

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
Lucyper
Newbie
Posts: 7
Joined: Sat Jun 17, 2023 8:07 pm
itch: python
Contact:

[SOLVED]Does renpy rollback support vars() ?

#1 Post by Lucyper »

I noticed that when I use the following structure:

Code: Select all

init python:
    class GameControl():
        def __init__(self):
            self.day = 0
            self.time = 0

        def foward(self, field, num):
            vars(self)[field] += num

default Game = GameControl()

label start:
    $ Game.foward('day', 5)
    # rollback there
If I do a rollback, the game keep adding value to the Game.day, And it happens with vars() function and the alternative self.__dict__ too
Last edited by Lucyper on Sun Feb 11, 2024 9:49 am, edited 1 time in total.

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Does renpy rollback support vars() ?

#2 Post by PyTom »

No. Using:

Code: Select all

setattr(self, field, getattr(self, field) + num)
should work.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Lucyper
Newbie
Posts: 7
Joined: Sat Jun 17, 2023 8:07 pm
itch: python
Contact:

Re: Does renpy rollback support vars() ?

#3 Post by Lucyper »

PyTom wrote: Sat Feb 10, 2024 11:56 pm No. Using:

Code: Select all

setattr(self, field, getattr(self, field) + num)
should work.
Thanks for the answer, I will use this alternative.

Post Reply

Who is online

Users browsing this forum: Alex, wizard_jpg