Pickling error when trying to save (Solved)

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
Code Monkey
Regular
Posts: 88
Joined: Tue Apr 03, 2012 9:17 am
Projects: Dandelion
Organization: Cheritz
Location: Seoul, South Korea
Contact:

Pickling error when trying to save (Solved)

#1 Post by Code Monkey »

Saving works sometimes, but sometimes I get the following error:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
PicklingError: Can't pickle <type 'function'>: attribute lookup __builtin__.function failed

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

Full traceback:
  File "C:\Program Files\Renpy-6.13.12\renpy\execution.py", line 265, in run
  File "C:\Program Files\Renpy-6.13.12\renpy\ast.py", line 632, in execute
  File "C:\Program Files\Renpy-6.13.12\renpy\python.py", line 972, in py_exec_bytecode
  File "common/00library.rpy", line 625, in <module>
  File "C:\Program Files\Renpy-6.13.12\renpy\ui.py", line 237, in interact
  File "C:\Program Files\Renpy-6.13.12\renpy\display\core.py", line 1803, in interact
  File "C:\Program Files\Renpy-6.13.12\renpy\display\core.py", line 2329, in interact_core
  File "C:\Program Files\Renpy-6.13.12\renpy\display\layout.py", line 714, in event
  File "C:\Program Files\Renpy-6.13.12\renpy\display\layout.py", line 714, in event
  File "C:\Program Files\Renpy-6.13.12\renpy\display\layout.py", line 714, in event
  File "C:\Program Files\Renpy-6.13.12\renpy\display\screen.py", line 300, in event
  File "C:\Program Files\Renpy-6.13.12\renpy\display\layout.py", line 714, in event
  File "C:\Program Files\Renpy-6.13.12\renpy\display\layout.py", line 174, in event
  File "C:\Program Files\Renpy-6.13.12\renpy\display\layout.py", line 174, in event
  File "C:\Program Files\Renpy-6.13.12\renpy\display\layout.py", line 714, in event
  File "C:\Program Files\Renpy-6.13.12\renpy\display\layout.py", line 174, in event
  File "C:\Program Files\Renpy-6.13.12\renpy\display\behavior.py", line 627, in event
  File "C:\Program Files\Renpy-6.13.12\renpy\display\behavior.py", line 211, in run
  File "common/00screen.rpy", line 1146, in __call__
  File "C:\Program Files\Renpy-6.13.12\renpy\loadsave.py", line 220, in save
  File "C:\Program Files\Renpy-6.13.12\renpy\loadsave.py", line 47, in dump
PicklingError: Can't pickle <type 'function'>: attribute lookup __builtin__.function failed

Windows-7-6.1.7601-SP1
Ren'Py 6.13.12.1728
Has anyone gotten this when saving before? I'm not entirely sure what I did to cause it. Any ideas or suggestions on how to fix it would be very much appreciated!
Last edited by Code Monkey on Thu Jun 07, 2012 8:52 pm, edited 1 time in total.

User avatar
Alex
Lemma-Class Veteran
Posts: 3093
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Pickling error when trying to save

#2 Post by Alex »

Try

Code: Select all

init python:
    config.use_cpickle = False
to get better error message.
The problem might be that you have a variable named exactly as function (for example - "say"). If so, just rename this variable.

Code Monkey
Regular
Posts: 88
Joined: Tue Apr 03, 2012 9:17 am
Projects: Dandelion
Organization: Cheritz
Location: Seoul, South Korea
Contact:

Re: Pickling error when trying to save

#3 Post by Code Monkey »

I did as you said and I did get a better error message. It points to a callback function and I renamed it but it still gives the same error. Perhaps some code would help. The callback function is defined in a class like so:

Code: Select all

@staticmethod
def transform_callback(d, st, at, **kwargs):
        for k, v in kwargs.iteritems():
                setattr(d, k, v)
        return 0
And then in some other method in the same class I call it. It gets curried, passed to a Transform, and that gets passed to the at_list param of renpy.show

Code: Select all

renpy.show('image_name', at_list=[Transform(function=renpy.curry(ImageDisplayHelper.transform_callback)(xpos=x_pos, ypos=y_pos, zoom=zoom_rate)), dissolve_in], layer=layer)
Hmm, what could it be? Have anymore suggestions?

User avatar
PyTom
Ren'Py Creator
Posts: 16093
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:

Re: Pickling error when trying to save

#4 Post by PyTom »

You probaably want to do:

Code: Select all

def transform_callback_(...):
    ...
transform_callback = staticmethod(transform_callback_)
I'm not 100% sure that will work. You may have to use a function instead of a staticmethod. Basically, pickling requires python be able to find the function from it's name. Certainly @staticmethod interferes - but simply being a static member of a class might also be problematic.
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

Code Monkey
Regular
Posts: 88
Joined: Tue Apr 03, 2012 9:17 am
Projects: Dandelion
Organization: Cheritz
Location: Seoul, South Korea
Contact:

Re: Pickling error when trying to save

#5 Post by Code Monkey »

Couldn't get that to work, so I removed the staticmethod and just made it a function and it works! Thanks a lot PyTom!

woahevil1
Newbie
Posts: 13
Joined: Wed Aug 19, 2015 5:58 am
Contact:

Re: Pickling error when trying to save (Solved)

#6 Post by woahevil1 »

Alright this gaming is looking great! A few problems though:

1. When your health is zero, it continues the game until you kill the enemy instead of taking you to the losers screen.


2. After the battle is finished, this error occurs when I try to save a game:
- I'm sorry, but an uncaught exception occurred.

While running game code:
File "renpy/common/00gamemenu.rpy", line 161, in script
$ ui.interact()
File "renpy/common/00gamemenu.rpy", line 161, in <module>
$ ui.interact()
File "renpy/common/00action_file.rpy", line 277, in __call__
renpy.save(fn, extra_info=save_name)
PicklingError: Can't pickle <type 'function'>: attribute lookup __builtin__.function failed

Any idea how to help?

Mutive
Veteran
Posts: 344
Joined: Tue Nov 21, 2017 2:23 am
Completed: Eidolon, Minion!, Love Furever, Epilogue
Contact:

Re: Pickling error when trying to save (Solved)

#7 Post by Mutive »

I seem to be having a similar problem following a while loop that I've created as a battle simulator. I can save before it, but not after I've run the battle (which takes place using a while loop). Do I need to change the loop to a function? (...argh...) Is there another way to handle it that would be easier? Thanks! I'm hitting my head against the wall trying to figure out why I can save only *before* while loops (and not after...)

(I've tried simplifying the while loop - written in Renpy vs. Python script - down to its bare bones in a dummy page and it's still not saving. So I think it's that, not some other bit of code (i.e. adding persistent states or whatever.) Will keep fiddling with it, but figure that if anyone has any ideas, I'm all ears! It would be good to get this bug taken care of!!!)

(Note: I also tried a for loop instead of a while, just to see if that was the issue, and the problem is persisting. Yargh!)
Enjoy Eidolon, my free to play game at: https://mutive.itch.io/eidolon, Minion! at: https://mutive.itch.io/minion or Epilogue at: https://mutive.itch.io/epilogue

Mutive
Veteran
Posts: 344
Joined: Tue Nov 21, 2017 2:23 am
Completed: Eidolon, Minion!, Love Furever, Epilogue
Contact:

Re: Pickling error when trying to save (Solved)

#8 Post by Mutive »

Anyway, wanted to follow up to note that I've gotten it to work!

The problem appeared to be that I imported the random module to help with the battles I was creating. I was using the command:

Code: Select all

$ import random
which caused the game to glitch.

Instead I used the command:

Code: Select all

init python:
import random
at the top of the game, which then ran smoothly! So learned my lesson re: importing Python modules!
Enjoy Eidolon, my free to play game at: https://mutive.itch.io/eidolon, Minion! at: https://mutive.itch.io/minion or Epilogue at: https://mutive.itch.io/epilogue

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

Re: Pickling error when trying to save (Solved)

#9 Post by Ocelot »

I advise against using random module in RenPy. It does not participate in rollbacks, and I am not sure if its state is saved.

RenPy itself provides random number generation faculties: https://www.renpy.org/doc/html/other.html#renpy-random
< < insert Rick Cook quote here > >

Mutive
Veteran
Posts: 344
Joined: Tue Nov 21, 2017 2:23 am
Completed: Eidolon, Minion!, Love Furever, Epilogue
Contact:

Re: Pickling error when trying to save (Solved)

#10 Post by Mutive »

I don't think the state is saved, but I'm okay with that seeing as I'm just using it as a combat generator. (Where the outcome will branch depending on whether the person survives the battle or not, then the random numbers are kind of useless anyway!)

With that said, thanks for the link to the random generator for Renpy. I'll have to use this from now on! ^_^
Enjoy Eidolon, my free to play game at: https://mutive.itch.io/eidolon, Minion! at: https://mutive.itch.io/minion or Epilogue at: https://mutive.itch.io/epilogue

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]