Save game Problems[SOLVED]


(billy2000) #1

Hello guys. So i almost finished my game and i tryed to implement finaly the save/load data. I writed the codes, i used a browser to open my game and i played abit so it can save my progress. I tryed to play the game again into the same browser but it didnt saved anything. I tryed to upload it on a site to try it out if the save works but same problem if i refresh the page. I dont really know what is wrong becose the load data (i think) works well(my variables get the default value),and also i get no errors. Here are the codes:

private function saveData():void	
	{
		Data.writeInt("TotCoins", G.Coins);
		Data.writeInt("life", G.LifeLvl);
		Data.writeInt("treasureBought", G.TreasureBought);
		Data.writeBool("lifeShop", G.LifeDed);
		Data.writeString("state", G.towerState);
		
		for (i = 1; i <= 9; i++) {
			changer = i + 0;
	        Data.writeBool(changer.toString(), G.Treasure[i]);
		}
		for (i = 1; i <= 9; i++) {
			changer = i + 0;
			Data.writeBool(changer.toString(), G.TreasureRelative[i]);
		}
		for (i = 1; i <= 99; i++) {
			changer = i + 100;
			Data.writeInt(changer.toString(), G.CoinsFinal[i]);
		}
		for (i = 1; i <= 21; i++) {
			changer = i + 10;
			Data.writeInt(changer.toString(), G.Levels[i]);
		}
	}
	private function loadData():void
	{
		G.Coins = Data.readInt("TotCoins", 0);
		G.LifeLvl = Data.readInt("life", 1);
		G.TreasureBought = Data.readInt("treasureBought", 0);
		G.LifeDed = Data.readBool("lifeShop", false);
		G.towerState = Data.readString("state", "no");//"no"//"all towers"
		
		G.Treasure.length = 10;
		G.TreasureRelative.length = 10;
		G.CoinsFinal.length = 106; 
		G.Levels.length = 22;
		
		for (i = 1; i <= 9; i++) {
			changer = i + 0;
	        G.Treasure[i] = Data.readBool(changer.toString(), false);
			
		}
		for (i = 1; i <= 9; i++) {
			changer = i + 0;
			G.TreasureRelative[i] = Data.readBool(changer.toString(), false);
			
		}
		for (i = 1; i <= 99; i++) {
			changer = i + 100;
			G.CoinsFinal[i] = Data.readInt(changer.toString(), 0);
		}
		for (i = 1; i <= 21; i++) {
			changer = i + 10;
			G.Levels[i] = Data.readInt(changer.toString(), 0);
		}
	}

(Bora Kasap) #2

You mean it doesn’t saving data second time(overwrite)?


(JP Mortiboys) #3

Are you calling Data.load() and Data.save()?

Have a read through the Data.as source code to see why you need to.


(billy2000) #4

@AlobarNon I meant it dosent save data at all. @NotARaptor No i didnt,the code i posted its everything i writed about saveing and loadeing data. Also this is my 1st time i try to do this so i dont know too much about saveing and loadeing >.<. Can you guys help me please? Thx.


(billy2000) #5

When do i use data.load() and when save.load()? I am just useing my loadData() at beggining of the game and saveData() after finisheing the level.


(billy2000) #6

Well how my save and load works is like this: The current world go into the SaveGameWorld and there i have those 2 funstions and i call them like this in the public function SaveGameWorld:

if (whatDo == "load") {
			loadData();
			Data.load();
		}
		if (whatDo == "save") {
			saveData();
			Data.save();//i tryed to put data.load() and data.save() right here as u can see but still nothing
		}

After that i just go in the world i need with another function.


(JP Mortiboys) #7

Try putting Data.load() before loadData (Data.load loads the session file from disk into an object, loadData then makes sense of it)


(billy2000) #8

IT WORKED. Thanks alot xD.