Remove function not working

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
Adrian_DVL
Regular
Posts: 141
Joined: Fri Mar 15, 2019 8:46 am
Completed: Clockwork Poison
Projects: Melodic Dates, Clockwork Poison: Salvation
Contact:

Remove function not working

#1 Post by Adrian_DVL »

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?

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2402
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Remove function not working

#2 Post by Ocelot »

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: 141
Joined: Fri Mar 15, 2019 8:46 am
Completed: Clockwork Poison
Projects: Melodic Dates, Clockwork Poison: Salvation
Contact:

Re: Remove function not working

#3 Post by Adrian_DVL »

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!

Post Reply

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot]