TStand90/roguelike_tutorial_revised

Using Shelve to save didn't work for me

Opened this issue · 4 comments

As the title says, the Shelve code didn't work for me. It created files named "savedgame.dat" and appended the extension ".dat" to the end, so I had "savedgame.dat.dat". This wouldn't load.

I was able to fix this by following the code found here and creating my own "savegames" folder.

This issue has been cropping up for some people and seems to depend on the Python version used.

I'm using Python 3.7 on VS Code, if that helps.

The problem occurs if shelve defaults to the dumb-dbm, instead of dmb.gnu or dmb.ndbm. dmb.dumb automatically creates .dat & .dir endings, which the other two don't. Afaik dumb is the only available dbm on windows by default, so the issue might be os-related if gnu or ndbm are available on unix-systems from the get-go.

For me (I'm using Python 3.6 on a Mac) it seems that the shelve.open command is automatically adding a .db extension when writing the savegame file, which lead to the aforementioned problem. os.path.isfile() simply looks for the text contained in the specified filename. My solution was quite simple. Keep the extension .db in line 16 if not os.path.isfile('savegame.db'): but in both def save_game and def load_game supply shelve.open() with only 'savegame' as the filename, without the extension.