> To: python-list@python.org > From: breamore...@yahoo.co.uk > Subject: Re: Writing game-state data... > Date: Fri, 9 Nov 2012 07:37:56 +0000 > > 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 Here's the full stack > trace: File "C:\Python Project\Roguelike.py", line 1048, in <module> main_menu() File "C:\Python Project\Roguelike.py", line 1030, in main_menu play_game() File "C:\Python Project\Roguelike.py", line 1007, in play_game player_action = handle_keys() File "C:\Python Project\Roguelike.py", line 717, in handle_keys quit_menu() #exit game File "C:\Python Project\Roguelike.py", line 698, in quit_menu save_game() File "C:\Python Project\Roguelike.py", line 909, in save_game file['map'] = map TypeError: 'type' object does not support item assignment >>> What I'm trying to do is figure out a way to get the game to save its >>> state; I compiled it to an EXE using py2exe, but after that, the game >>> refuses to hold onto its data. Thanks for all the help!
-- http://mail.python.org/mailman/listinfo/python-list