Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 oliver-jones · Jun 28, 2011 at 04:13 PM · saveloadplayerprefsx

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

Comment
Add comment
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

1 Reply

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

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.

Comment
Add comment · Show 3 · 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 oliver-jones · Jun 28, 2011 at 04:49 PM 0
Share

What names am I using that are different? They all look fine to me?

avatar image Eric5h5 · Jun 28, 2011 at 05:15 PM 0
Share

@Oliver Jones:

 PlayerPrefsX.SetBool("$$anonymous$$apStats.mapOne.CompleteAwards"

 PlayerPrefsX.GetBool("mapOne.CompleteAwards"
avatar image Eric5h5 · Jun 28, 2011 at 05:19 PM 0
Share

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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

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


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