Writing game-state data...

Graham Fielding frednotbob at hotmail.ca
Fri Nov 9 08:20:54 CET 2012





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? 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20121108/1d91f85e/attachment.html>


More information about the Python-list mailing list