Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #33001
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Subject | Re: Writing game-state data... |
| Date | 2012-11-09 07:37 +0000 |
| References | <SNT139-W18E5B74880062FFEECD3F5A3680@phx.gbl> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3480.1352446732.27098.python-list@python.org> (permalink) |
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.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Writing game-state data... Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-11-09 07:37 +0000
csiph-web