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.
Lucyper
Newbie
Posts: 9 Joined: Sat Jun 17, 2023 8:07 pm
Projects: The Mad Scientist
Deviantart: Lucyper4u
itch: https://lucyp-r.itch
Contact:
#1
Post
by Lucyper » Sat Feb 10, 2024 9:41 pm
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.
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:
#2
Post
by PyTom » Sat Feb 10, 2024 11:56 pm
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: 9 Joined: Sat Jun 17, 2023 8:07 pm
Projects: The Mad Scientist
Deviantart: Lucyper4u
itch: https://lucyp-r.itch
Contact:
#3
Post
by Lucyper » Sun Feb 11, 2024 9:48 am
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.
Users browsing this forum: Ahrefs [Bot] , Google [Bot]