0

I'm looking for an efficient way to save my game coded in python. I've looked at pickle, but I'm not sure it will suit my needs as there is a lot of info that needs to be saved.

The way I understand pickle is it will take whatever I give it and dump it into a file, which sounds great. But not only do I have the player character to save, theres the rooms that the character has already been, the state of the rooms, if the user opened up treasure chests, etc. And if I understand pickle correctly, I would have to input each room manually for that to work.

Is there a better way to do this? Would I be better off creating a database of some kind? Or am I just not using pickle correctly?

jmarkmurphy
  • 11,030
  • 31
  • 59
Macimoar
  • 69
  • 2
  • 8
  • Please show some code, where you try to pickle. In general pickle is great to save objects, so why don't you create a class player and (a class room maybe..) add the achievements as attributes and pickle the object? – NewNewton Feb 17 '18 at 20:21

1 Answers1

1

Perhaps I'm missing something, but why not put all of the data you mention into a dictionary. It may even be a multi-level dictionary. Something like:

{
"player_info":{"name":"Bart", ..}, 
"current_state_of_game":{"cur_location":"library", "prior_room":"kitchen", ..}
}

Then pickle that?

kdragger
  • 436
  • 1
  • 5
  • 16