[Tutor] Best way to save a D&D-like game's state?

boB Stepp robertvstepp at gmail.com
Fri May 21 20:25:29 EDT 2021


I am contemplating the design of a D&D-like game where I will
prototype various ideas I have in Python.  Currently I am pondering
how such games typically have their state saved.  I imagine there will
be plenty of custom data types, which represent the state of the game
world when the players save.  I imagine the data involved could reach
sizable proportions, depending on how complex and rich the game
becomes.  The first thing that comes to mind is the pickle module,
which my understanding is that it can save and restore any custom data
types done in Python.  Next that comes to mind is JSON, but my
understanding is that it is limited in what it can save and restore
without additional work by the programmer.  Still staying in the
standard library I suppose an SQLite database could be made to work.

Questions:

1)  First off, am I thinking along the correct lines of doing this, or
is there a better way?

2)  If it does become true that sizable amounts of data need to be
stored, which of the above options is most performant?  Thinking about
this I suppose that in the case of large amounts of world data one
would want to divide up the data into logical units and only load what
is currently needed at any point in the game.

3)  Algorithmically, how would one perform incremental saves?  I know
this is done by many programs, so that only the changes to the
original data are stored, which saves (pun intended) on the amount of
data that needs to be saved.

4)  I am not adverse to considering third party libraries.  If I do
so, YAML also comes to mind.  I have no idea what other formats might
be worth considering.  I hope XML is not a serious option as I have
heard that it can turn into a mess with data files not easily parsable
by human readers.  Though I must add that some of the programs I work
with at work use XML and I have had no difficulty reading and editing
their data files at need in small ways, so perhaps I am unduly
prejudiced against XML?

5)  If this project proceeds to fruition then it is entirely possible
that portions or all of it will need to be rewritten in a more
hardware performant language.  If that proves to become the case will
that alter any of your answers to the above questions?

TIA!
boB Stepp


More information about the Tutor mailing list