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.

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to