Search Unity

Playerprefs not working?

Discussion in 'BlackBerry' started by dberroa, Oct 21, 2013.

  1. dberroa

    dberroa

    Joined:
    Dec 16, 2012
    Posts:
    146
    EDIT: Solved - This was a coding error on my part. Once that was fixed, PlayerPrefs seem to be working fine.

    I've added a few playerprefs via PlayerPrefs.SetInt and then PlayerPrefs.Save and when I close the app by sliding my finger up and hitting the X to close the app, the settings are not there when I load up again on the device.

    Has anyone else had playerprefs working on Blackberry?

    I also found someone else that had an issue with PlayerPrefs: http://hutonggames.com/playmakerforum/index.php?topic=5021.0
     
    Last edited: Oct 24, 2013
  2. AlexThibodeau

    AlexThibodeau

    Unity Technologies

    Joined:
    Jul 23, 2013
    Posts:
    309
    Hey there! I haven't gotten a chance to look into this myself yet unfortunately. It would be awesome if you could submit this as a bug using the bug reporting system to get it into the queue of things that need looking at. It's easier for me to track things in the bug system rather than forum threads. :)
     
  3. dberroa

    dberroa

    Joined:
    Dec 16, 2012
    Posts:
    146
    I'll submit it when I get home from work. I'm wondering if I'm doing it wrong though. I was under the impression you just set it and then save and that was it. Is there anything else I have to call?
     
  4. daisySa

    daisySa

    Joined:
    Dec 29, 2011
    Posts:
    341
    It's working fine for me on my Z10. You're also doing a GetInt when you re-enter your app, right?

    GameManager.difficulty = PlayerPrefs.GetInt("savedDifficulty");
     
  5. dberroa

    dberroa

    Joined:
    Dec 16, 2012
    Posts:
    146
    Thanks Daisy for your response.

    I relooked over my code and saw that I was changing the playerprefs on an NGUI value changed on a radio button group. Due to this, the whole entire group save was getting called overwriting my selection. By making this to on click, it worked.

    So it seems playerprefs are working, sorry for the mistake.

    Thanks to everyone.
     
  6. DFT-Games

    DFT-Games

    Joined:
    Jun 24, 2010
    Posts:
    454
    Actually something is off here: I have this published as well, but it's not saving the data at all... the app works fine already on iOS and Android, so the code is ok: this is quite a problem because if people buy the non consumable items they don't really have that working :(

    Is there some memory option that has to be set for BB?
     
  7. dberroa

    dberroa

    Joined:
    Dec 16, 2012
    Posts:
    146
    Could you post the code?
     
  8. DFT-Games

    DFT-Games

    Joined:
    Jun 24, 2010
    Posts:
    454
    Sure, but there is nothing wrong with the code, it works on all other platforms:
    Code (csharp):
    1.  public static void Save()
    2.     {
    3.   PlayerPrefs.SetInt("ammo", ammo);
    4.   PlayerPrefs.SetInt("gold", gold);
    5.   PlayerPrefs.SetString("last", System.DateTime.Now.Ticks.ToString ());
    6.   PlayerPrefs.SetFloat("music", AudioController.GetCategoryVolume("Music"));
    7.   PlayerPrefs.SetFloat("sfx", AudioController.GetCategoryVolume("SFX"));
    8.   PlayerPrefs.SetInt("double", doubleCoins ? 1 : 0);
    9.   PlayerPrefs.SetInt("ads", hasAds ? 1 : 0);
    10.   PlayerPrefs.Save();
    11.     }
    12.    
    13.     public static void Read()
    14.     {
    15.   ammo = PlayerPrefs.GetInt("ammo", 5);
    16.   gold = PlayerPrefs.GetInt("gold", 100);
    17.   AudioController.SetCategoryVolume("Music",PlayerPrefs.GetFloat("music", 0.5f));
    18.   AudioController.SetCategoryVolume("SFX",PlayerPrefs.GetFloat("sfx", 0.75f));
    19.   lastRun = System.TimeSpan.FromTicks(long.Parse(PlayerPrefs.GetString("last", System.DateTime.Now.Ticks.ToString())));
    20.   doubleCoins = (PlayerPrefs.GetInt("double", 0) == 0 ? false : true);
    21.   hasAds = (PlayerPrefs.GetInt("ads", 1) == 0 ? false : true);
    22.     }
    As you can see it's quite straight forward. These static methods are called here and there when needed, like when leaving the Settings screen, when switching from Menu to Game and viceversa, when any purchase is successful... and so on.

    Still banging my head on this one :(
     
  9. dberroa

    dberroa

    Joined:
    Dec 16, 2012
    Posts:
    146
    Hmm I'm not sure either. You wrote it pretty much exactly how I did for mine.

    Only thing I could suggest at this point is put a Debug.Log line in those functions and see if they are hit. That was the problem with mine, they were never called or double called.
     
  10. DFT-Games

    DFT-Games

    Joined:
    Jun 24, 2010
    Posts:
    454
    In such a case it wouldn't work on iOS and Android either :) Anyway I did find the solution: checking the file sharing box in the build settings has fixed the problem... no idea why :/
     
  11. dberroa

    dberroa

    Joined:
    Dec 16, 2012
    Posts:
    146
    Yeah not sure either as I don't have that selected and mine works.
     
  12. AlexThibodeau

    AlexThibodeau

    Unity Technologies

    Joined:
    Jul 23, 2013
    Posts:
    309