Preserving object's original address when restoring from shelf

wolf at one.net wolf at one.net
Sun Jun 25 11:06:21 EDT 2000


Hi All,

First, a quick background. I'm writing a text adventure writing system
in Python and I'm having some trouble with the save/restore system.

My problem is when I restore an object with this line of code:

   __GameModule__.__dict__[VariableName] = SavedGame[VariableName]

   where __GameModule__ is the top level module
         VariableName is the name of the object
         SavedGame is the open shelf

it does indeed restore the object--but it changes the object's address
(ID #). Unfortunately the object is referenced by *many* other objects
in the game. For example the object 'Hill' would be referenced by any
location that leads to Hill, and these references still point to the
old Hill.

Am I being clueless here? Is there some simple way to restore objects
that doesn't invoke this problem?

One final note, I don't know if it matters, but the system is set up
with layered modules, each module using an import from from the module
beneath. For example:

TQ imports * from PAWS, Universe, TQLib.
TQLib imports * from Universe, PAWS
Universe imports * from PAWS

This avoids the need to include a module reference each time an object
is used, this is important since the system is designed to let
non-programmers write games. (PAWS and Universe are unchanging
librarires, TQLib and TQ are written for each game)

Would it help to have each module save/restore its own dictionary and
then do another IMPORT * FROM statement? How would this impact memory
storage, would it cause memory leaks or would Python garbage collect
correctly?

I would really appreciate any help on this one!
Respectfully,

Wolf

"The world is my home, it's just that some rooms are draftier than
others". -- Wolf



More information about the Python-list mailing list