Can't erase save file



  • Hello Everyone,

    I'm trying to delete a save and then load an empty file so the player can start the game fresh but it is not working on native builds. It works only on Flash.

    Steps are:

    • I play a little to save some progress.
    • Then I erase the save file and it's variables.
    • I close the game and start it again.
    • The save file still has the data from the first step.

    The code to erase the save file is the following. It is triggered by a button:

    function releaseOk(e:MouseEvent):Void
    {
    	trace("delete save" + FlxG.save.erase());
    	FlxG.save.data.lastLevelCompleted = null;
    	FlxG.save.data.levelsScoresData = null;
    	FlxG.save.data.levelsStarsData = null;
    	FlxG.save.flush(0, onFlushComplete);
    }
    
    function onFlushComplete(r:Bool):Void
    {
    	FlxG.switchState(new SplashState());
    }
    

    To load the save I'm using:

    public function loadGameData():Void
    {
    	
    	//inicia variables
    	Reg.lastLevelUnlocked = 0;
    	
    	Reg.levelsScoresData = [];
    	
    	Reg.levelsStarsData = [];
    	
    	// carga la data
    	if (FlxG.save.data.lastLevelCompleted != null)
    	{
    		
    		Reg.lastLevelUnlocked = FlxG.save.data.lastLevelCompleted;
    		
    		Reg.levelsScoresData = FlxG.save.data.levelsScoresData;
    		
    		Reg.levelsStarsData = FlxG.save.data.levelsStarsData;
    		
    		FlxG.log.add("loaded. last level completed: " + FlxG.save.data.lastLevelCompleted);
    	}
    
    	trace("load Game Data last level " + FlxG.save.data.lastLevelCompleted + Reg.lastLevelUnlocked 
    	+ " levels levelsStarsData " + Reg.levelsStarsData 
    	+ " levels score " + Reg.levelsScoresData);
    	
    }
    

    And to save:

      function saveGameData():Void
      {
    	trace("saveGameData");
    	if (Reg.level >= Reg.lastLevelUnlocked)
    	{
    		Reg.lastLevelUnlocked = Reg.level +1;
    	}
    	
    	Reg.scoreLevel = Reg.coinsCollected + Std.int(Math.max(0, Reg.timeGoalLevel - Std.int(Reg.timePlayingLevel))) + Reg.itemsCollected;
    	Reg.levelsScoresData.insert(Reg.level, Reg.scoreLevel);
    	
    	//estrellas
    	var st1 = "on";
    	var st2 = "off";
    	var st3 = "off";
    	if (Reg.coinsCollected >= Reg.totalCoins)
    	{
    		st2 = "on";
    	}
    	if (Reg.timePlayingLevel <= Reg.timeGoalLevel)
    	{
    		st3 = "on";
    	}
    	Reg.levelsStarsData.insert(Reg.level, [st1, st2, st3]);
    	
    	FlxG.save.data.lastLevelCompleted = Reg.lastLevelUnlocked;
    	FlxG.save.data.levelsScoresData = Reg.levelsScoresData;
    	FlxG.save.data.levelsStarsData = Reg.levelsStarsData;
    	FlxG.save.flush();
    	
    	FlxG.log.add("saved");
    }


  • I got no problem with that. (neko)
    Try testing with only one variable.



  • The problem was with this line:

    trace("delete save" + FlxG.save.erase());

    I deleted it and it works fine now.


Log in to reply