Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Daniel G · Jul 17, 2013 at 05:19 PM · javascriptoptimizationplayerprefs

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

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Daniel G · Jul 17, 2013 at 05:22 PM 0
Share

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.

avatar image markedagain · Jul 17, 2013 at 07:38 PM 0
Share

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

avatar image Daniel G · Jul 17, 2013 at 08:01 PM 0
Share

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$$

avatar image Daniel G · Jul 18, 2013 at 01:44 AM 0
Share

@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!

avatar image markedagain · Jul 18, 2013 at 01:57 AM 0
Share

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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);

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Daniel G · Jul 21, 2013 at 06:29 PM 0
Share

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!

avatar image markedagain · Jul 21, 2013 at 06:45 PM 0
Share

javascript, not java ;) very important not to mix it up

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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

How many variables can I store using PlayerPrefs 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges