i have a text based game that gets pretty complex. I am trying to make a save game feature. I have a custom class Game which is pretty complex and holds all the game logic and state info. It creates object instances of other custom classes World, Room, Action, BaseObject.
The following code is how i am saving the game to the shared object and loading it back. It does not throw any errors(which took me a long time to figure out), but when i save, close the app, and then reopen, and try to load, it does not seem to have saved any of the state information about the game object.
its as if when i load, it successfully gets the game object from the savedGame:SharedObject but it is a new instance of a game object, not a persistent version from the last save. Is my game object too complex. It would be great if i could just save the whole game object in the Shared object and recoup it later.
Also, if i save and then load in the same app session it doesn't throw me back to the beginning of the game. i don't get it!
ActionScript Code:
private function initApplication():void{
registerClassAlias("classes.Game", Game);
savedGame=SharedObject.getLocal("savedGameFile");
this.game=new Game();
this.gameRunning=true;
refreshGame();
}
private function doInput():void
{
if(input.text=="save"){
savedGame.clear();
savedGame.data.GA=this.game;
savedGame.flush();
}else if(input.text=="load"){
this.game=savedGame.data.GA;
}else{
this.game.update(input.text);
}
this.refreshGame();
}