Multiple PlayerPref strings?

Hello. How can I store/display multiple copies of the same string using PlayerPrefs (for a local high score table)? Thanks

EDIT- Here is my playerpref script

function Update () 
    var Arcade : String = System.String.Format("{0}{1}{2}_score", Arcade.ModeInt, Arcade.DifficultyInt, Arcade.CharacterInt);
    PlayerPrefs.SetInt(Arcade, Stats.Score);

How can I store multiple copies of the same string using PlayerPrefs?

I guess what you really want to do is store an array of items? See ArrayPrefs on wiki!


var scores = PlayerPrefsX.GetIntArray("Scores");

Otherwise, this is my best direct answer to your question:

Use a different key. See the docs on PlayerPrefs.


var sameString = "Same String";

PlayerPrefs.SetString("Copy 1", sameString);
PlayerPrefs.SetString("Copy 2", sameString);
PlayerPrefs.SetString("Copy 3", sameString);
PlayerPrefs.SetString("Copy 4", sameString);

In this example we store the same string in 4 different keys.

As a response to your comment, you could change your code a bit to make it a little more maintainable:

function MakeKey(string variable) : String
    var mode = Arcade.ModeInt;
    var skill = Arcade.DifficultyInt;
    var player = Arcade.CharacterInt;
    var key = String.Format("{0} {1} {2} {3}", mode, skill, player, variable);
    return key;

function SetInt(string variable, int value) 
    var key = MakeKey(variable);
    PlayerPrefs.SetInt(key, value);

function GetInt(string variable) : int
    var key = MakeKey(variable);
    return PlayerPrefs.GetInt(key);

function Start()
    SetInt("score", Stats.Score);

Notice that I added " " between your integers in your key string. This is because without some padding, you might access wrong variable in some cases!

  • Imagine if you had the values 1, 11, 11, score. the key would become 11111_score.
  • Imagine also if you had the values 11, 1, 11, score. the key would also become 11111_score.
  • With a space in between, they are distinguishable: "1 11 11 score" and "11 1 11 score"