Real Time Clock Pickle Error

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
User avatar
CoolerMudkip
Regular
Posts: 40
Joined: Tue Jul 24, 2018 9:15 pm
Completed: Memories~ Megami no hogo-sha [Demo]
Projects: Northward
Tumblr: CoolerMudkip
Github: ztc0611
itch: MorallyGay
Location: United States, East Coast
Discord: MorallyGay#5861
Contact:

Real Time Clock Pickle Error

#1 Post by CoolerMudkip »

Alright, so I have a moment where the game uses the time of the computer to change some dialogue, and that works properly, but after that happens, the game is unable to be saved or reloaded. It's a pickle error, but I'm not sure how to rectify it.

Getting Time:

Code: Select all

python:
        import time
        year1, month1, day1, hour1, minute1, second1, dow1, doy1, dst1 = time.localtime()
My attempts to remove it afterwards:

Code: Select all

python:
        del time
        year1 = 0
        month1 = 0
        day1 = 0
        hour1 = 0
        minute1 = 0
        second1 = 0
        dow1 = 0
        doy1 = 0
        dst1 = 0
        time = 0
Full Error Message (In this instance triggered by attempting to save):

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "renpy/common/00gamemenu.rpy", line 173, in script
    $ ui.interact()
  File "renpy/common/00gamemenu.rpy", line 173, in <module>
    $ ui.interact()
  File "renpy/common/00action_file.rpy", line 361, in __call__
    renpy.save(fn, extra_info=save_name)
Exception: Could not pickle <module 'time' (built-in)>. (perhaps renpy.game.log.log[44].stores['store']['time'] = <module 'time' (built-in)>)

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

Full traceback:
  File "renpy/common/00gamemenu.rpy", line 173, in script
    $ ui.interact()
  File "D:\Games\Ren'py\renpy\ast.py", line 862, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "D:\Games\Ren'py\renpy\python.py", line 1888, in py_exec_bytecode
    exec bytecode in globals, locals
  File "renpy/common/00gamemenu.rpy", line 173, in <module>
    $ ui.interact()
  File "D:\Games\Ren'py\renpy\ui.py", line 287, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "D:\Games\Ren'py\renpy\display\core.py", line 2635, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
  File "D:\Games\Ren'py\renpy\display\core.py", line 3437, in interact_core
    rv = root_widget.event(ev, x, y, 0)
  File "D:\Games\Ren'py\renpy\display\layout.py", line 992, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "D:\Games\Ren'py\renpy\display\transition.py", line 45, in event
    return self.new_widget.event(ev, x, y, st)  # E1101
  File "D:\Games\Ren'py\renpy\display\layout.py", line 992, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "D:\Games\Ren'py\renpy\display\layout.py", line 992, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "D:\Games\Ren'py\renpy\display\screen.py", line 689, in event
    rv = self.child.event(ev, x, y, st)
  File "D:\Games\Ren'py\renpy\display\layout.py", line 992, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "D:\Games\Ren'py\renpy\display\layout.py", line 239, in event
    rv = d.event(ev, x - xo, y - yo, st)
  File "D:\Games\Ren'py\renpy\display\layout.py", line 992, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "D:\Games\Ren'py\renpy\display\layout.py", line 239, in event
    rv = d.event(ev, x - xo, y - yo, st)
  File "D:\Games\Ren'py\renpy\display\layout.py", line 992, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "D:\Games\Ren'py\renpy\display\layout.py", line 239, in event
    rv = d.event(ev, x - xo, y - yo, st)
  File "D:\Games\Ren'py\renpy\display\behavior.py", line 906, in event
    return handle_click(self.clicked)
  File "D:\Games\Ren'py\renpy\display\behavior.py", line 841, in handle_click
    rv = run(action)
  File "D:\Games\Ren'py\renpy\display\behavior.py", line 315, in run
    return action(*args, **kwargs)
  File "renpy/common/00action_file.rpy", line 361, in __call__
    renpy.save(fn, extra_info=save_name)
  File "D:\Games\Ren'py\renpy\loadsave.py", line 402, in save
    dump((roots, renpy.game.log), logf)
  File "D:\Games\Ren'py\renpy\loadsave.py", line 48, 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 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 286, in save
  File "/home/tom/ab/x64lucid-deps/install/lib/python2.7/pickle.py", line 600, in save_list
  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 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 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 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 292, in save
  File "D:\Games\Ren'py\renpy\python.py", line 1974, in module_pickle
    raise Exception("Could not pickle {!r}.".format(module))
Exception: Could not pickle <module 'time' (built-in)>. (perhaps renpy.game.log.log[44].stores['store']['time'] = <module 'time' (built-in)>)

Windows-8-6.2.9200
Ren'Py 6.99.14.3.3347
Sun Nov 25 23:25:26 2018

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Real Time Clock Pickle Error

#2 Post by Remix »

Have you tried putting the import in an init python block instead or just addressing the time module through renpy.ast.time instead?

Short of seeing more/all the time based code all we can really say is that you appear to be saving the entire time module rather than just an instance of a datetime object...
Frameworks & Scriptlets:

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Real Time Clock Pickle Error

#3 Post by trooper6 »

Hey Remix, where is renpy.ast.time documented? I can't find it anywhere.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
CoolerMudkip
Regular
Posts: 40
Joined: Tue Jul 24, 2018 9:15 pm
Completed: Memories~ Megami no hogo-sha [Demo]
Projects: Northward
Tumblr: CoolerMudkip
Github: ztc0611
itch: MorallyGay
Location: United States, East Coast
Discord: MorallyGay#5861
Contact:

Re: Real Time Clock Pickle Error

#4 Post by CoolerMudkip »

This is all of the code. I tried the init thing and it didn't change anything. Just for clarification, it crashes on save even after this part of the VN has passed and the time module has been unloaded.

Code: Select all

    python:
        import time
        year1, month1, day1, hour1, minute1, second1, dow1, doy1, dst1 = time.localtime()

    if month1 == 1:
        $ diamonth = "January"
    if month1 == 2:
        $ diamonth = "February"
    if month1 == 3:
        $ diamonth = "March"
    if month1 == 4:
        $ diamonth = "April"
    if month1 == 5:
        $ diamonth = "May"
    if month1 == 6:
        $ diamonth = "June"
    if month1 == 7:
        $ diamonth = "July"
    if month1 == 8:
        $ diamonth = "August"
    if month1 == 9:
        $ diamonth = "September"
    if month1 == 10:
        $ diamonth = "October"
    if month1 == 11:
        $ diamonth = "November"
    if month1 == 12:
        $ diamonth = "December"

    if hour1 >= 2 and hour1 <= 5:
       #Night Dialogue
    if hour1 >= 6 and hour1 <= 11:
        #Morning Dialogue
    if hour1 >= 12 and hour1 <= 16:
        #Afternoon Dialogue
    if hour1 >= 17 and hour1 <= 19:
        #Evening Dialogue 
    if hour1 >= 20 and hour1 <= 24:
        #Night Dialogue 
    if hour1 == 1:
        #Night Dialogue 

    python:
        del time
        year1 = 0
        month1 = 0
        day1 = 0
        hour1 = 0
        minute1 = 0
        second1 = 0
        dow1 = 0
        doy1 = 0
        dst1 = 0
        time = 0

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Real Time Clock Pickle Error

#5 Post by Remix »

trooper6 wrote: Mon Nov 26, 2018 11:49 am Hey Remix, where is renpy.ast.time documented? I can't find it anywhere.
The ast module imports the time module into its namespace, so you can avoid an import call by using it from within that module, much like renpy.python.rng rather than importing random...
Semi useful for one liner calls in non production code, just be aware there is always the possibility that a namespace might be updated and no longer import the module you want.

CoolerMudkip:

I'd suggest moving the import into an init python and testing if the return of time.localtime() is just a tuple or a reference to the time module

Code: Select all

init python:
    import time
    

label start:

    $ time_tuple = time.localtime()

    $ diamonth, hour1 = _strftime("%B", time_tuple), time_tuple[3]
    #
    # _strftime is Ren'Py's version of Python's strftime that is recoded to play nice with translation
    # Basically, using it allows us just to translate month names and day names once

    if 6 <= hour1 <= 11:
        #Morning Dialogue
        "morning"
    elif 12 <= hour1 <= 16:
        #Afternoon Dialogue
        "afternoon"
    elif 17 <= hour1 <= 19:
        #Evening Dialogue 
        "evening"
    else:
        #Night Dialogue 
        "night"

    "[diamonth!q] ([time_tuple!q])"
Frameworks & Scriptlets:

User avatar
CoolerMudkip
Regular
Posts: 40
Joined: Tue Jul 24, 2018 9:15 pm
Completed: Memories~ Megami no hogo-sha [Demo]
Projects: Northward
Tumblr: CoolerMudkip
Github: ztc0611
itch: MorallyGay
Location: United States, East Coast
Discord: MorallyGay#5861
Contact:

Re: Real Time Clock Pickle Error

#6 Post by CoolerMudkip »

@Remix Tried that, still getting the same issues. It can reload on the "[diamonth!q] ([time_tuple!q])" line just fine, but not if it is after the if-else tree, which leads me to believe it may be an issue with knowing which line to be able to rollback to?

Example:

Code: Select all

init python:
    import time
label start:

    $ time_tuple = time.localtime()

    $ diamonth, hour1 = _strftime("%B", time_tuple), time_tuple[3]
    #
    # _strftime is Ren'Py's version of Python's strftime that is recoded to play nice with translation
    # Basically, using it allows us just to translate month names and day names once
    
    "1 [diamonth!q] ([time_tuple!q])" #<<-- I CAN SAVE/RELOAD HERE

    if 6 <= hour1 <= 11:
        #Morning Dialogue
        "morning"
    elif 12 <= hour1 <= 16:
        #Afternoon Dialogue
        "afternoon"
    elif 17 <= hour1 <= 19:
        #Evening Dialogue 
        "evening"
    else:
        #Night Dialogue 
        "night"
        
    $ renpy.block_rollback() # (See note below)
    "2 [diamonth!q] ([time_tuple!q])" #<<-- BUT NOT HERE AND BEYOND
    
I attempted to run renpy.block_rollback() after the tree to see if that would make it stop, but it persists.
(Also, thank you for simplifying the mess that was the month name situation, it was a pain to work with.)

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Real Time Clock Pickle Error

#7 Post by Remix »

Works fine here (exactly the above in a new project with a few extra dialogue lines after) so the error must be elsewhere.

Is the error still time pickle?
If so, search your entire script for references to time and maybe get lucky.

Also, try:

Code: Select all

init python:
    config.use_cpickle = False
and check traceback

Other than that we'd pretty much need the full script to help debug more.
Frameworks & Scriptlets:

User avatar
CoolerMudkip
Regular
Posts: 40
Joined: Tue Jul 24, 2018 9:15 pm
Completed: Memories~ Megami no hogo-sha [Demo]
Projects: Northward
Tumblr: CoolerMudkip
Github: ztc0611
itch: MorallyGay
Location: United States, East Coast
Discord: MorallyGay#5861
Contact:

Re: Real Time Clock Pickle Error

#8 Post by CoolerMudkip »

Alright, tried all of these things to try and make sure I properly isolated the problem:
(Sorry for the over-detailed explanation of how I figured this out, but it may help someone in the future.)

Tried to disable everything related to the time module, including loading it at all: Saving/Reloading works.
Tried to disable any script that references it, but still importing time, Saving/Reloading works.
Enabled this code, but not anything that uses it at all (see below), Saving/Reloading works.

Code: Select all

$ time_tuple = time.localtime()
$ diamonth, hour1 = _strftime("%B", time_tuple), time_tuple[3]
Enabled the code that checks for time, but not the code that I tried to make to unload it (see below), Saving/Reloading works.
Enabled the code that unloads it, Saving/Reloading breaks. (not until after the call), but the VN doesn't error out on any of those lines.

Code: Select all

python:
        del time
        year1 = 0
        month1 = 0
        day1 = 0
        hour1 = 0
        minute1 = 0
        second1 = 0
        dow1 = 0
        doy1 = 0
        dst1 = 0
        time = 0
Then I realized that was unneeded anyway, and had forgotten to delete it after you gave me a working example. Pretty sure the issue was with attempting to unload the time module, which I thought may help because I at some point read that Ren'py doesn't save python modules well.
It works now! (Well, at least from my moderate amount of testing, attempting to make it break, anyway.)

Turns out that code, which I made to attempt to fix the problem in the first place, just broke it more. Whoops. Guess I should have copied what you put more directly. Solved, thank you so much for your assistance!

Post Reply

Who is online

Users browsing this forum: Nozori_Games