[Tutor] my text adventure

david din22 at earthlink.net
Sun Dec 4 14:28:36 CET 2005


thanks. i had actually coded this almost exactly the same. i'll try to make my
questions more specific. i am able to pickle and restore world. which is a dictionary
of coordinates : room objects. when i look at the savefile that pickle generates i can
see all my descriptions and exits. however when i reload my world gets back all
the rooms that were created with dig. but the rooms don't have their exits or descriptions.
is pickle the right tool for this? can i pickle.dump more than one thing to the same
savefile? or how could i go about creating a structure that holds room, coords, descriptions
and exits? and then pickle and unpickle that. 
or would it be better to write my own functions to write everything to a file and not use
pickle at all? eventually my program will have many more things to keep track of and
i am thinking that the saving and restoring of a programs state (is that correct usage?)
could be important in many different programs.
  ----- Original Message ----- 
  From: Dan Lowe 
  To: david 
  Cc: tutor at python.org 
  Sent: Sunday, December 04, 2005 1:24 AM
  Subject: Re: [Tutor] my text adventure




  On Dec 3, 2005, at 9:40 PM, david wrote:


    sorry i forgot a subject line. i have looked at the pickle module and was able to pickle world.
    but i can't figure how to restore everything. 


  import pickle


  def save_game(state, filename):
      file = open(filename, 'w')
      pickle.dump(state, file)
      file.close()


  def load_game(filename):
      file = open(filename, 'r')
      state = pickle.load(file)
      file.close()
      return state


  save_game(world, 'mygame')


  world = load_game('mygame')


  -- 
  logic (n.): the art of being wrong with confidence.





-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20051204/683cfbf2/attachment.htm


More information about the Tutor mailing list