# Need help making a save game class

**URL:** <https://forum.kirupa.com/t/need-help-making-a-save-game-class/314375>\
**Category:** Uncategorized\
**Created:** [September 26, 2010, 10:10pm UTC](https://forum.kirupa.com/t/need-help-making-a-save-game-class/314375 "2010-09-26T22:10:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pcehnaids](https://avatars.discourse-cdn.com/v4/letter/p/90ced4/32.png) [@pcehnaids](https://forum.kirupa.com/u/pcehnaids)\
**Post date:** [September 26, 2010, 10:10pm UTC](https://forum.kirupa.com/t/need-help-making-a-save-game-class/314375/1 "2010-09-26T22:10:12Z")

</div>

I am an amateur programmer attempting to make an adventure game and I need a little help. The basic setup is a panoramic engine that loads external swf’s when you click on a specific area. I need a way to globally store the states of the puzzle variables so that you can save your progress.The basic idea for my save game class is as follows:

- This class is instantiated in the main document class

```auto
var saveGame:SaveGame = new SaveGame();

```

which loads the inventory, music, and swfLoader classes.

- I have 2 arrays in which one stores the variable name, and one stores the var data.

```auto
gameVarArray:Array //Variable name
gameVarData:Array //Variable data

```

- I then use a public method to add a new variable

```auto
addGameVar(vName:String, vValue:Object) 

```

which loads vName into gameVarArray and vValue into gameVarData with respective indices. I also use a getVar(vName) and setVar(vName, vValue) methods to retrieve and change variable values.

- I then use a “SharedObject” to dump these arrays to a local file for later retrieval.

My questions are these:

1. Is this a good way to store global puzzle variables for a game?
2. How do I implement the method in the external swf’s. (when i put saveGame.getVar(vName) on the external swf timeline, it says that it is accessing an “undefined property saveGame”).

I would greatly welcome any help, this is definitely pushing my understanding of OOP.
