title: Video game save/load problems with python pickle (not loading instances)
body: <p>I'm currently working on a text adventure in python (this language just because it's the one I know), and I'm finding that creating and loading savefiles removes some of the mecahnics I've made. I'll include the problematic code here, rather than all of elements that work fine. it's mainly to do with classes and how instances are 'pickled'.</p>
  <p>Here are some of the classes I've created:</p>
  <pre><code>class Player:
  def __init__(self, name):
      self.sack = []
      self.kit = []
      self.equipped = []
      self.log = []
      self.done = []
  class Weapon:
  def __init__(self, name, price, minattack, maxattack):
      self.name = name
      self.price = price
      self.minattack = minattack
      self.maxattack = maxattack
  class Food:
  def __init__(self, name, price, healthadd):
      self.name = name
      self.price = price
      self.healthadd = healthadd
  class Quest:
  def __init__(self, name, requirement, num, gold, npc, place, give_text, prog_text, comp_text, done_text):
      self.name = name
      self.requirement = requirement
      self.num = num
      self.score = 0
      self.gold = gold
      self.npc = npc
      self.place = place
      self.give_text = give_text
      self.prog_text = prog_text
      self.comp_text = comp_text
      self.done_text = done_text
  </code></pre>
  <p>The instances in the Player class I've included here are just the ones that are appended by other mechanics with Weapons, Food and Quests. The code includes regions where Weapons, Food and Quests are populated (though working on a separate assets file might tidy things up a bit).</p>
  <p>Here's how the save/load functions work currently:</p>
  <pre><code>def save(lastplace):
  clear()
  with open('savefile', 'wb') as f:
      PlayerID.currentplace = lastplace.name
      pickle.dump(PlayerID, f)     
      print(&quot;Game saved:\n&quot;)
      print(PlayerID.name)
      print(&quot;(Level %i)&quot; % (PlayerID.level))
      print(lastplace.name)
      print('')
  option = input(&quot;&gt;&gt;&gt; &quot;)
  goto(lastplace)
  def load():
  clear()
  if os.path.exists(&quot;savefile&quot;) == True:
      with open('savefile', 'rb') as f:
          global PlayerID
          PlayerID = pickle.load(f)
          savedplace = PlayerID.currentplace
          savedplace = locations[savedplace]
          goto(savedplace)        
  else:
      print(&quot;You have no save file for this game.&quot;)
      option = input('&gt;&gt;&gt; ')
      main()
  </code></pre>
  <p>It's worth noting that upon entry to the game, PlayerID (you) becomes a global variable. You might begin to see some of the issues here, or rather the overarching issue. Essentially, the pickling process serialises all of the possible class types stored in lists within the class of Player just get appended by their names, thus removing their class properties when loaded back into the game.</p>
  <p>Is there a pythonic way to ensure that class instances are saved for a future load so that they can still behave as classes, particularly when stacked inside the class of Player? I appreciate this is more of an editorial rather than a question by its length, but any help would be hugely appreciated.</p>