I'm getting this exception where the game is complaining about not being able to import a pickle module:
This is the save() method from PyScenario (line #49 in red):
Line #49 in red. The self.triggers field contains a list of instances of a class ("Trigger"), by the way. (The rest of the dictionary contains stuff related to RFC mod that I use as a base for my own work.)
The exception occurs both when I start up a new game and after I make changes to the .py files during game. The reason for pickling the triggers in the first place is because I don't want them to reload every time the Python files are initialized. So I thought I'd store then in scriptDict so that this method can unpickle them on load:
The weird thing is that it worked yesterday, but I've been fiddling with the CvRFCEventHandler today and now I get this exception. Any ideas what causes it?
Also, this is the call from the handler:
Any help would be appreciated, as I haven't done any pickling before and really have no clue as to what is happening...
Spoiler :
Traceback (most recent call last):
File "CvEventInterface", line 23, in onEvent
File "CvRFCEventManager", line 108, in handleEvent
File "CvRFCEventManager", line 119, in _handleDefaultEvent
File "CvRFCEventHandler", line 233, in onPreSave
File "PyScenario", line 49, in save
cPickle
.
PicklingError
:
Can't pickle <type 'Boost.Python.instance'>: import of module Boost.Python failed
ERR: Python function onEvent failed, module CvEventInterface
Code:
from CvPythonExtensions import *
import CvUtil
...
import cPickle as pickle
...
gc = CyGlobalContext()
...
class Setup:
def __init__(self):
self.triggers = []
...
...
def save(self):
scriptDict = pickle.loads( gc.getGame().getScriptData() )
scriptDict['lTriggers'] = self.triggers
[COLOR="Red"]gc.getGame().setScriptData( pickle.dumps(scriptDict) )[/COLOR]
The exception occurs both when I start up a new game and after I make changes to the .py files during game. The reason for pickling the triggers in the first place is because I don't want them to reload every time the Python files are initialized. So I thought I'd store then in scriptDict so that this method can unpickle them on load:
Code:
def load(self):
scriptDict = pickle.loads( gc.getGame().getScriptData() )
self.triggers = scriptDict['lTriggers']
Also, this is the call from the handler:
Code:
from PyScenario import Setup
PyScenario = Setup()
...
def __init__(self, eventManager):
...
eventManager.addEventHandler("OnPreSave",self.onPreSave)
...
def onPreSave(self, argsList):
PyScenario.save()