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.
-
Adrian_DVL
- Regular
- Posts: 114
- Joined: Fri Mar 15, 2019 8:46 am
- Completed: Clockwork Poison
- Projects: Melodic Dates, Clockwork Poison: Salvation
-
Contact:
#1
Post
by Adrian_DVL » Thu Sep 02, 2021 5:51 am
Hi!
My problem is simple and quite absurd, I must say, but I must be missing something that I'm not seeing. I have this class with some functions:
Code: Select all
class Qlist(renpy.store.object):
def __init__(self):
self.quests = []
self.done = []
def add(self, quest):
self.quests.append(quest)
def addop(self, quest):
self.quests.insert(0, quest)
def done(self, quest):
self.quests.remove(quest)
def opdone(self, quest):
global opsd
self.quests.remove(quest)
self.done.append(quest)
opsd += 1
This used to work perfectly but I don't know where the heck I touched in the code that now the 'done' function is not working. Every time I execute that function, for instance "qlist.done(q1)", it gives me an error saying 'RevertableList' object is not callable. However, when I execute directly "qlist.quest.remove(q1)", it works as a charm and the "q1" object is removed from the list "qlist.quests". Why could this be? Why my function isn't working anymore?
-
Ocelot
- Eileen-Class Veteran
- Posts: 1883
- Joined: Tue Aug 23, 2016 10:35 am
- Github: MiiNiPaa
- Discord: MiiNiPaa#4384
-
Contact:
#2
Post
by Ocelot » Thu Sep 02, 2021 6:51 am
So there is roughly what happens when you create a Qlist object(pseudocode not an actual code):
Code: Select all
Qlist.__create__:
# class initialization
self.add = <function>(someaddress)
self.addop = <function>(someaddress)
self.opdone = <function>(someaddress)
self.done = <function>(someaddress)
# executing init
self.done = []
self.quests = []
Do you see the problem now? You are redefining
done member in init method. In Python methods are member objects like everything else. You can do anything with them, including overwriting them.
< < insert Rick Cook quote here > >
-
Adrian_DVL
- Regular
- Posts: 114
- Joined: Fri Mar 15, 2019 8:46 am
- Completed: Clockwork Poison
- Projects: Melodic Dates, Clockwork Poison: Salvation
-
Contact:
#3
Post
by Adrian_DVL » Thu Sep 02, 2021 7:23 am
Ocelot wrote: ↑Thu Sep 02, 2021 6:51 am
So there is roughly what happens when you create a Qlist object(pseudocode not an actual code):
Code: Select all
Qlist.__create__:
# class initialization
self.add = <function>(someaddress)
self.addop = <function>(someaddress)
self.opdone = <function>(someaddress)
self.done = <function>(someaddress)
# executing init
self.done = []
self.quests = []
Do you see the problem now? You are redefining
done member in init method. In Python methods are member objects like everything else. You can do anything with them, including overwriting them.
You're absolutely right. What I've done is mix two classes unintentionally. Fixed it by creating a done list outside the class. Thank you!
Users browsing this forum: Google [Bot]