Hi,
I searched forum for playerprefs topics - but still I’m not sure about few things. I’m using (imo heavy method) an array of all in-game switches (int’s for scripted action), there is about… 150 int’s defined in game data base (master script with all datas - descriptions blah blah). During save I’m putting all possible variables from PlayerPrefs into array, then writing values and names of them into xml. During Load I’m first deleting all playerprefs, then read names and values from xml and crate new playerprefs variables with name and values from xml document. And this method works fine, it takes about 0.3sec for save or load - but I have 2x3.5Gz and 8GB RAM. I’m wondering - how this method will work on “normal” machine? My budy after clicking save or load has “never ending loading” Also I’m thinking - is that method safe? And if it’s not, how could I make it better/faster? In fact my project is realy small - all I need is to store tons of int’s to know what player done, and what is still ahead of him
Also I heard, that PlayerPrefs has limit different on each platform - does anyone knows those limits?
Sample codes:
I’m creating an arrays of current playerprefs:
for(i=0;i<=99;i++){
if(PlayerPrefs.HasKey("switch"+i)){
currSwitchesNames.Add("switch"+i);
currSwitchesValues.Add(PlayerPrefs.GetInt("switch"+i));
}
if(PlayerPrefs.HasKey("switchUse"+i)){
currSwitchesNames.Add("switchUse"+i);
currSwitchesValues.Add(PlayerPrefs.GetInt("switchUse"+i));
}
if(PlayerPrefs.HasKey("item"+i+"Collected")){
currSwitchesNames.Add("item"+i+"Collected");
currSwitchesValues.Add(PlayerPrefs.GetInt("item"+i+"Collected"));
}
else if(!PlayerPrefs.HasKey("switch"+i) !PlayerPrefs.HasKey("switchUse"+i) !PlayerPrefs.HasKey("item"+i+"Collected")){
currSwitchesNames.Add("null");
currSwitchesValues.Add(0);
}
}
Than all of them are wrote in hard-coded way (99 times for names and values):
sData._iUser0.sNames0 = currSwitchesNames[ 0 ];
sData._iUser0.sNames1 = currSwitchesNames[ 1 ];
sData._iUser0.sNames2 = currSwitchesNames[ 2 ];
sData._iUser0.sNames3 = currSwitchesNames[ 3 ];
sData._iUser0.sNames4 = currSwitchesNames[ 4 ];
... .
In case of load:
if(sData._iUser0.sNames0 != "null"){PlayerPrefs.SetInt(sData._iUser0.sNames0 , sData._iUser0.sValues0 );}
if(sData._iUser0.sNames1 != "null"){PlayerPrefs.SetInt(sData._iUser0.sNames1 , sData._iUser0.sValues1 );}
...
And now I have a quetions to some proffessionals - how hard and un-proffessional this method is and how can I improve it? Are PlayerPrefs safe for tons of data?
Sry for english in this post.
Kind regards,
Artur