Search Unity

Question Check String in PlayerPrefs

Discussion in 'Scripting' started by Andreas12345, Mar 15, 2021.

  1. Andreas12345

    Andreas12345

    Joined:
    Oct 17, 2013
    Posts:
    526
    Code (CSharp):
    1. Debug.Log("List of unlock championship exist" + PlayerPrefs.GetString("chamionnshipState"));
    2.             if ("chamionnshipState".Contains("True,False,False,False,False,False,False,"))
    3.             {
    4.                 print("blabla");
    5.             }
    I try to check the trues and false of a PlayerPrefString.
    but i get no "blabla" in console :)

    any thoughts?
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    You need to check against the string you get from PlayerPrefs using that key, not the key itself, which you're doing now. that is, you need PlayerPrefs.GetString around the string before .Contains.
     
    Joe-Censored and Andreas12345 like this.
  3. Andreas12345

    Andreas12345

    Joined:
    Oct 17, 2013
    Posts:
    526
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,752
    Also, rather than sprinkling this sort of noise all over your program and project and risking misspelling stuff, try this approach... much cleaner:

    Here's an example of simple persistent loading/saving values using PlayerPrefs:

    https://pastebin.com/icJSq5zC

    Useful for a relatively small number of simple values.

    ALSO:

    Beware this word is traditionally spelled "Championship"

    If you misspell lots of stuff, then when you use Ctrl-F to find stuff, you won't find it.
     
    Andreas12345 likes this.
  5. Andreas12345

    Andreas12345

    Joined:
    Oct 17, 2013
    Posts:
    526
    i know, the misspelling, i have a reason for it.
    I use it to unlock achievements, and i understand what happen.
    It is easier for me when i really know what i do :)