Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: Writing game-state data... (http://www.velocityreviews.com/forums/t954360-re-writing-game-state-data.html)

Mark Lawrence 11-09-2012 07:37 AM

Re: Writing game-state data...
 
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.



All times are GMT. The time now is 05:25 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.