- Home /
PlayerPrefsX - Not Saving?
Hello,
I'm trying to work on an award system, the first award I'm working on is "completing a level" award.
At the end of the level, a menu pops up saying congrats - you've completed this level. This then sets a boolean called "CompleteAward" to true. So when I go back to my main menu, under my award menu, I can see my award is unlocked (completed). This all works great, but I can't seem to save this boolean's status.
The weird thing is, is that I'm using the same system for 'Game Stats' - which basically tells you how many enemies you've killed throughout the game - and this works, it saves and loads.
The only difference I am using between the two are PlayerPrefs and PlayerPrefsX (which allow me to save booleans). I just cant understand why it wont save/load the PrefsX.
Okay, well here is a snippet of my pop up end of level menu: (Menu.js) - this is in my LEVEL
function OnGUI(){
if(Controller.RoundComplete == true && paused){
// ---- Review Awards ---- \\
// complete map
if(saveComplete){
CompleteAward();
saveComplete = false;
}
}
// Continue Button \\
if(GUI.Button(Rect(Screen.width/2 - 400/2 ,Screen.height-300, 400, 100), "Continue")){
Time.timeScale = 1;
// Game Stats \\
PlayerPrefs.SetInt("Credits.XP", Credits.XP);
PlayerPrefs.SetInt("TurretStats.turretsPlace", TurretStats.turretsPlace);
PlayerPrefs.SetInt("TurretStats.turretsDestroyed", TurretStats.turretsDestroyed);
PlayerPrefs.SetInt("TurretStats.turretsRepaired", TurretStats.turretsRepaired);
PlayerPrefs.SetInt("TurretStats.turretsUpgrades", TurretStats.turretsUpgrades);
// Award Stats \\
PlayerPrefsX.SetBool("MapStats.mapOne.CompleteAwards", MapStats.mapOne.CompleteAwards);
Application.LoadLevel (0 + 1);
}
}
private var saveComplete : boolean = true;
function CompleteAward(){
var externalSpawn = FindObjectOfType(Spawn);
var externalStat = FindObjectOfType(MapStats);
if(externalSpawn.MapSelected == 1){
MapStats.mapOne.CompleteAwards = true;
//PlayerPrefsX.SetBool("externalStat.mapOne.CompleteAwards", externalStat.mapOne.CompleteAwards);
}
}
Here is my MapStats (basically holds the info for my awards): - this is on my MAIN MENU
class MapOne {
static var CompleteAwards : boolean;
static var DefenderAwards : boolean;
static var BuilderAwards : boolean;
static var WageAwards : boolean;
static var PeakAwards : boolean;
}
static var mapOne : MapOne = MapOne();
function Awake(){
mapOne.CompleteAwards = PlayerPrefsX.GetBool("mapOne.CompleteAwards");
}
Can someone please help me out here.
Thanks
Answer by Eric5h5 · Jun 28, 2011 at 04:46 PM
It doesn't actually have anything to do with PlayerPrefsX (which is just a wrapper for PlayerPrefs)...you're using different names for saving and loading the bool. So when you try to load it, the key doesn't exist and you get the default value.
What names am I using that are different? They all look fine to me?
@Oliver Jones:
PlayerPrefsX.SetBool("$$anonymous$$apStats.mapOne.CompleteAwards"
PlayerPrefsX.GetBool("mapOne.CompleteAwards"
I should also mention...judging from the names, you have a separate class for each map? It would be a lot simpler if you used arrays. You can use ArraysPrefs2 to save and load arrays: http://www.unifycommunity.com/wiki/index.php?title=ArrayPrefs2
Your answer
Follow this Question
Related Questions
SimpleJSON array problem 0 Answers
C# Issues with either PlayerPrefs.SetVariable or UnityEvent.Invoke 1 Answer
How do I find a Prefab after I Replaced said Prefab? 1 Answer
Cannot load a saved game 1 Answer
Saving/Load using menu C# 1 Answer