[SOLVED] PicklingError: Can't pickle <type 'code'>

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
Victorius
Regular
Posts: 30
Joined: Thu Jan 14, 2021 7:02 pm
Projects: Astral Lust
Github: Victorius-Astral
Contact:

[SOLVED] PicklingError: Can't pickle <type 'code'>

#1 Post by Victorius »

So I've got this error when trying to save, at the beginning I thought it was caused by lambda, but I've removed it and used renpy.curry instead, still the error appears. Also I've checked and another screen with lambda can be saved and works normally (in previous game ver.):

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "renpy/common/00keymap.rpy", line 463, in script
    python hide:
  File "renpy/common/00keymap.rpy", line 463, in <module>
    python hide:
  File "renpy/common/00keymap.rpy", line 482, in _execute_python_hide
    renpy.save("_reload-1", "reload save game")
PicklingError: Can't pickle <type 'code'>: attribute lookup __builtin__.code failed

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

Full traceback:
  File "renpy/common/00keymap.rpy", line 463, in script
    python hide:
  File "C:\Users\Gamer\Desktop\Astral Lust\renpy-7.3.5-sdk/renpy/ast.py", line 922, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "C:\Users\Gamer\Desktop\Astral Lust\renpy-7.3.5-sdk/renpy/python.py", line 2218, in py_exec_bytecode
    exec(bytecode, globals, locals)
  File "renpy/common/00keymap.rpy", line 463, in <module>
    python hide:
  File "renpy/common/00keymap.rpy", line 482, in _execute_python_hide
    renpy.save("_reload-1", "reload save game")
  File "C:\Users\Gamer\Desktop\Astral Lust\renpy-7.3.5-sdk/renpy/loadsave.py", line 413, in save
    reraise(t, e, tb)
  File "C:\Users\Gamer\Desktop\Astral Lust\renpy-7.3.5-sdk/renpy/loadsave.py", line 399, in save
    dump((roots, renpy.game.log), logf)
  File "C:\Users\Gamer\Desktop\Astral Lust\renpy-7.3.5-sdk/renpy/loadsave.py", line 49, in dump
    cPickle.dump(o, f, cPickle.HIGHEST_PROTOCOL)
PicklingError: Can't pickle <type 'code'>: attribute lookup __builtin__.code failed

Windows-10-10.0.19041
Ren'Py 7.4.4.1439
Astral Lust 0.1.4b
Wed Apr 14 19:42:06 2021
The thing is I can't save anywhere. Not only in changed screen. Anyone has any ideas what can cause this? I mean it says code, but everything is a code.
EDIT:
The error appears only when saving after I enter this label at least once:

Code: Select all

label show_storage(sel_tab = "mat"):
    python:

        # Make av_me an empty list
        av_me = []

        # make list of available menus
        for m in storage_menus_sort:

            # Compile evaluation expression
            expr = storage_menus[m][2] + ">=" + str(storage_menus[m][3])
            expr = compile(expr, "menus", "eval")

            # Check if requirement satisfied, if yes add menu to av_me
            if eval(expr):
                av_me.append(m)


    # Call storage screen
    show screen storage(available_menus = av_me, sel_tab = sel_tab)

    # Return to the previous label
    return
Last edited by Victorius on Wed Apr 14, 2021 2:59 pm, edited 2 times in total.

Victorius
Regular
Posts: 30
Joined: Thu Jan 14, 2021 7:02 pm
Projects: Astral Lust
Github: Victorius-Astral
Contact:

Re: PicklingError: Can't pickle <type 'code'>

#2 Post by Victorius »

Solved! I've been removing code, and by elimination I've found the problem:

Code: Select all

expr = compile(expr, "menus", "eval")
It seems pickle can't save code objects (or at least I think it's it). I've removed compile line and it works now.

Post Reply

Who is online

Users browsing this forum: Google [Bot]