- Home /
PlayerPrefs Scripting Logic Help!
Hello, I am using JavaScript I Would like to know if i should (at the end of each level) have a script that looks like this:
function OnCollisionEnter () {
//CHECK Last loaded level
}
if (loaded level == 1) {
PlayerPrefs.SetInt("LevelOneData", 1);
//Using a Seperate script for this, this is a function in that script gotten from PreviewLabs
//that is supposed to be faster than unity's Save(); function! See Question for details*
PlayerPrefs.Flush();
}
if (loaded level == 2) {
PlayerPrefs.SetInt("LevelTwoData", 1);
//Using a Seperate script for this, this is a function in that script gotten from PreviewLabs
//that is supposed to be faster than unity's Save(); function! See Question for details*
PlayerPrefs.Flush();
}
if (loaded level == 3) {
PlayerPrefs.SetInt("LevelThreeData", 1);
//Using a Seperate script for this, this is a function in that script gotten from PreviewLabs
//that is supposed to be faster than unity's Save(); function! See Question for details*
PlayerPrefs.Flush();
}
//IMAGINE 150 more of these...
OR is this going to RESAVE every and ALL Player prefs? Which obviously if i had 50 of them that would be serious lag)
SIDE NOTE: However i found this company that made this excellent script to help reduce lag for iOS! PreviewLabs
Or should i have a different script for Each level to ENSURE it only saves that ONE playerPref? Like this:
//OR should i do this, This would be attached to the finish line collider, there would be one
//for each level and the only thing that
//would change is the name of the script and the
//"LevelOneData" to say "LevelTwoData" ect...
function OnCollisionEnter () {
PlayerPrefs.SetInt("LevelOneData", 1);
}
My two questions when i thought of this was: 1. Will the One big script Save ALL the player prefs every time? Or will it only save the one that changed, If it saves them all at once WITH the Knowledge of Me using that Script (PreviewLabs) thats supposed to SPEED up the saving Process, Would the LARGE script be okay to use? 2. Does it make a difference WHERE i put the .Flush(); or .Save();? It saves ALL the variables in all player pref scripts correct? Is there away around this or does there even need to be?
Thanks for your help! I know this is a tough question, Thats why i need help :P
Daniel
So I want to ensure the app saves the data before application quit in case of crash that is WHY i am using the SAVE or FLUSH function after every level!
Sorry if that was confusing! I know it saves player prefs on application quit too.
im unsure what the exact question is, for my prefrence if i had so many levels i would comeup with a dynamic way to save each levels info ins$$anonymous$$d of hard coding everything per if statement.
one thing i can say is, make your own middle man function to save the playerprefs. like this if u notice a lag in the normal methode all u have to do is how 1 function saves the data and the rest of the game will follow.
are the names of your levels saved somewhere ? maybe u can use that variable to populate your save data
Thank you for your comment but with out an example, Im lost as to where you are going and what your trying to say! Sorry! If you have experience in this specific area please ask specific questions. Thanks $$anonymous$$
@markedagain Brilliant, however since I am new to PlayerPrefs, Can you translate what you wrote into JavaScript? $$anonymous$$y C# comprehension is rather nonexistent at the moment :P But i do know a good big of java :D If you Write this as an answer in JavaScript I will accept it, It looks like your on the right track! Thanks!
dont inter mix the word java with javascript. as for translating to javascript :p , i haven't done javascripting in to long for me to say something credible on that point
Answer by markedagain · Jul 17, 2013 at 08:17 PM
if you are going to do alot of saves and loads, you should create your own function, so that if ever you change the logic of how u save stuff, u dont have to edit it everwhere
public static void SaveLevelInfo(string lvlName , PlayerPrefs playerPrefs){}
then if your name of your level is saved somewhere in your onCollision save your data to your new function GameLevel.SaveLevelInfo(nameOfLevel, PlayerPrefs);
Thanks for the help even if it wasn't in java, and i see what your saying :D im doing it already actually :P Thanks!
javascript, not java ;) very important not to mix it up
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
PlayerPrefs Help 1 Answer
Is There Such a Thing as an RTS Starter Pack? 1 Answer
Pain in the ass 2 Answers