Temple of The Roguelike Forums
Development => Programming => Topic started by: Hundertzehn on November 18, 2014, 03:55:33 PM
-
I am at the stage where I finally want to save the current game on disk.
I have an instance of a map object. In it, there is a list of instances of the tile object. The tile object has a list of instances of the thing object, one list entry for every thing on that tile. Things can have inventories, thus more lists with more thing instances.
A few loops and "pickle" could solve this problem, but I wonder if there is a more elegant solution.
-
https://docs.python.org/2/library/pickle.html#what-can-be-pickled-and-unpickled
The documentation says that you can pickle lists, tuples, etc as long as they contain only "picklable" objects. So, I guess, you should try to pickle the entire thing. Unless there are some bad objects, the pickle module should recursively serialize it all. Did you try to do it?
-
As soon as you start doing it right, it works! ;)
-
I always thought pickle couldn't handle recursive nested lists or other data structures with cycles of pointers, but it looks like it actually works. Huh.