[plt-scheme] Saving and loading an instance of a class (boardgame)

From: David Moberg (kaddkaka at gmail.com)
Date: Mon May 17 04:53:27 EDT 2010

Hi, this is probably a noob question, but I have found good help and
activity here so I hope I can get help with this other issue with a board
game me and my friend is programming :)

The program consist of an instance (current-game) of our class game% and a
GUI (frame%). And we want to add a save option to the menu.

;This is almost the first line of code in the program
(define current-game (new game&))

Can we print current-game to a file with a command such as:

(define out (open-output-file "save001.sav"))
(write current-game out)
(close-output-port out)

and load it with

(define in (open-input-file "save001.sav"))
(set! current-game (read-line in))
(close-input-port in)

Is it possible to do something similar in a method to the game% class (refer
to the instance itself)? Or do we have to store all members of the game%
instance one by one?
Will the loading get screwed up with we change a minor thing in the

// David (does anyone want to take a look on our code? This is our first
(graphical!) game and we would love all the help we can get. :))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20100517/c32acecf/attachment.html>

Posted on the users mailing list.