[solved] Can't pickle class

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
martingerdes
Regular
Posts: 26
Joined: Sun Oct 07, 2018 5:14 am
Contact:

[solved] Can't pickle class

#1 Post by martingerdes »

This happens if I try to save my game after my first event started:
(with "config.use_cpickle = False" for a more useful error message)

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "renpy/common/00action_file.rpy", line 372, in __call__
    renpy.save(fn, extra_info=save_name)
PicklingError: Can't pickle <class 'store.evaluate'>: it's not found as store.evaluate

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "renpy/common/_layout/screen_load_save.rpym", line 35, in script
    $ ui.interact()
  File "/mnt/Data/eigeneDateien/Programme/renpy-7.1.0-sdk/renpy/ast.py", line 882, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "/mnt/Data/eigeneDateien/Programme/renpy-7.1.0-sdk/renpy/python.py", line 1913, in py_exec_bytecode
    exec bytecode in globals, locals
  File "renpy/common/_layout/screen_load_save.rpym", line 35, in <module>
    $ ui.interact()
  File "/mnt/Data/eigeneDateien/Programme/renpy-7.1.0-sdk/renpy/ui.py", line 289, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "/mnt/Data/eigeneDateien/Programme/renpy-7.1.0-sdk/renpy/display/core.py", line 2662, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
  File "/mnt/Data/eigeneDateien/Programme/renpy-7.1.0-sdk/renpy/display/core.py", line 3467, in interact_core
    rv = root_widget.event(ev, x, y, 0)
  File "/mnt/Data/eigeneDateien/Programme/renpy-7.1.0-sdk/renpy/display/layout.py", line 995, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "/mnt/Data/eigeneDateien/Programme/renpy-7.1.0-sdk/renpy/display/transition.py", line 47, in event
    return self.new_widget.event(ev, x, y, st)  # E1101
  File "/mnt/Data/eigeneDateien/Programme/renpy-7.1.0-sdk/renpy/display/layout.py", line 995, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "/mnt/Data/eigeneDateien/Programme/renpy-7.1.0-sdk/renpy/display/layout.py", line 995, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "/mnt/Data/eigeneDateien/Programme/renpy-7.1.0-sdk/renpy/display/screen.py", line 697, in event
    rv = self.child.event(ev, x, y, st)
  File "/mnt/Data/eigeneDateien/Programme/renpy-7.1.0-sdk/renpy/display/layout.py", line 995, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "/mnt/Data/eigeneDateien/Programme/renpy-7.1.0-sdk/renpy/display/layout.py", line 241, in event
    rv = d.event(ev, x - xo, y - yo, st)
  File "/mnt/Data/eigeneDateien/Programme/renpy-7.1.0-sdk/renpy/display/layout.py", line 995, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "/mnt/Data/eigeneDateien/Programme/renpy-7.1.0-sdk/renpy/display/layout.py", line 995, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "/mnt/Data/eigeneDateien/Programme/renpy-7.1.0-sdk/renpy/display/behavior.py", line 907, in event
    return handle_click(self.clicked)
  File "/mnt/Data/eigeneDateien/Programme/renpy-7.1.0-sdk/renpy/display/behavior.py", line 842, in handle_click
    rv = run(action)
  File "/mnt/Data/eigeneDateien/Programme/renpy-7.1.0-sdk/renpy/display/behavior.py", line 308, in run
    new_rv = run(i, *args, **kwargs)
  File "/mnt/Data/eigeneDateien/Programme/renpy-7.1.0-sdk/renpy/display/behavior.py", line 315, in run
    return action(*args, **kwargs)
  File "renpy/common/00action_file.rpy", line 372, in __call__
    renpy.save(fn, extra_info=save_name)
  File "/mnt/Data/eigeneDateien/Programme/renpy-7.1.0-sdk/renpy/loadsave.py", line 404, in save
    dump((roots, renpy.game.log), logf)
  File "/mnt/Data/eigeneDateien/Programme/renpy-7.1.0-sdk/renpy/loadsave.py", line 50, in dump
    pickle.dump(o, f, pickle.HIGHEST_PROTOCOL)
  File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/pickle.py", line 1370, in dump
  File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/pickle.py", line 224, in dump
  File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/pickle.py", line 286, in save
  File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/pickle.py", line 548, in save_tuple
  File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/pickle.py", line 286, in save
  File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/pickle.py", line 649, in save_dict
  File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/pickle.py", line 681, in _batch_setitems
  File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/pickle.py", line 331, in save
  File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/pickle.py", line 419, in save_reduce
  File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/pickle.py", line 286, in save
  File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/pickle.py", line 649, in save_dict
  File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/pickle.py", line 681, in _batch_setitems
  File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/pickle.py", line 331, in save
  File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/pickle.py", line 413, in save_reduce
  File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/pickle.py", line 633, in _batch_appends
  File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/pickle.py", line 331, in save
  File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/pickle.py", line 396, in save_reduce
  File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/pickle.py", line 286, in save
  File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/pickle.py", line 748, in save_global
PicklingError: Can't pickle <class 'store.evaluate'>: it's not found as store.evaluate

Linux-4.15.0-36-generic-x86_64-with-debian-buster-sid
Ren'Py 7.1.0.882
Ashford Academy Redux 0.0.1
Sun Dec 16 22:16:41 2018
Alright, so the problem is, that it is looking for a base class "evaluate", while in fact this is a child class of "event" ?
Well, why is it doing that?

I am using the dating simulation engine (dse-event_dispatcher.rpy) code in my game, and have modified it to fit.

Code: Select all

init -100 python:

    # A list of all of the events that the system knowns about,
    # it's filtered to determine which events should run when.
    all_events = [ ]

    class event(object):

        def __repr__(self):
            return '<event ' + self.name + '>'

        def __init__(self, name, *args, **kwargs):

            self.name = name
            self.priority = kwargs.get('priority', 100)

            exprs = [ ]
            for i in args:
                if isinstance(i, basestring):
                    exprs.append(event.evaluate(i))
                else:
                    exprs.append(i)

            self.exprs = exprs

            all_events.append(self)
            
        # This evaluates the expression given as an argument, and the
        # returns true if it evaluates to true.
        class evaluate(event_check):

            def __init__(self, expr):
                self.expr = expr

            def eval(self, name, valid):
                return eval(self.expr)
That one point in the initialization "exprs.append(event.evaluate(i))" is the only point in the code I use any object called "evaluate" so I am pretty sure I am not overloading the term.
And while I have modified dse quite a bit, the code I copied here is unchanged from the original. So it's probably my usage of the code that is at fault. What should I be on the lookout for? How could I go about debugging it? (The one experiment I did is trying to rename evaluate to evaluate2, and the class name in the stack trace dutyfully changed ...)
Last edited by martingerdes on Sun Dec 16, 2018 6:59 pm, edited 1 time in total.

martingerdes
Regular
Posts: 26
Joined: Sun Oct 07, 2018 5:14 am
Contact:

Re: Can't pickle class

#2 Post by martingerdes »

And solved:
Saving events does not work.
Fixed by adding a dictionary of all the events in addition to the list all_events, saving the event name in the variable, and looking up event properties by way of the dictionary.

Sorry for the noise, but maybe it will end up helpful for somebody else.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot], Ikaros_OwO