Re: Writing game-state data...

Discussion in 'Python' started by Mark Lawrence, Nov 9, 2012.

  1. On 09/11/2012 07:20, Graham Fielding wrote:
    >
    > Hey, folks, me again! I've been puzzling over this for a while now: I'm trying to write data to a file to save the state of my game using the following function: def save_game():
    > #open a new empty shelve (possibly overwriting an old one) to write the game data
    > file_object = open('savegame.sav', 'wb')
    > file['map'] = map
    > file['objects'] = objects
    > file['player_index'] = objects.index(player) #index of player in objects list
    > file['inventory'] = inventory
    > file['game_msgs'] = game_msgs
    > file['game_state'] = game_state
    > file['stairs_index'] = objects.index(stairs)
    > file['dungeon_level'] = dungeon_level
    > file.close() However, while 'savegame.sav' is created in the directory I specify, the function dies on file['map'] = map. This is the end of the stack trace:
    > File "C:\Python Project\Roguelike.py", line 966, in save_game
    > file['map'] = map
    > TypeError: 'type' object does not support item assignment Now, the map is randomly generated -- could that be an issue? Should I just scrap the current system and use pickle?
    >


    Please always give the complete stack trace, it's provided for a
    purpose. Here I'll grope around in the dark and guess that you need
    file_object = shelve.open(...

    --
    Cheers.

    Mark Lawrence.
     
    Mark Lawrence, Nov 9, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. BlackHawke
    Replies:
    12
    Views:
    1,623
    Andrew Thompson
    Jan 26, 2004
  2. judith
    Replies:
    0
    Views:
    1,820
    judith
    Nov 1, 2006
  3. Max Kubierschky
    Replies:
    10
    Views:
    1,909
    pabloreda
    Mar 31, 2007
  4. Ian Kelly

    Re: Writing game-state data...

    Ian Kelly, Nov 9, 2012, in forum: Python
    Replies:
    0
    Views:
    269
    Ian Kelly
    Nov 9, 2012
  5. Prasad, Ramit

    RE: Writing game-state data...

    Prasad, Ramit, Nov 9, 2012, in forum: Python
    Replies:
    0
    Views:
    257
    Prasad, Ramit
    Nov 9, 2012
Loading...

Share This Page