Save the Multiple name using the PlayerPrefs function

Hi,

I have used below code for saving the multiple names using the array. But i have the issue in this. when i save the second name in array the first name also change. I dont know how to solve this, please help me to do this.

PlayerPrefs.SetString("JOKE"+no[0], "one");
		PlayerPrefs.SetString("JOKE"+no[1], "two");
		
		GUI.Label(new Rect(10, 100, 100, 30), PlayerPrefs.GetString("JOKE"+no[0]));
		GUI.Label(new Rect(10, 140, 100, 30), PlayerPrefs.GetString("JOKE"+no[1]));

Thanks.

Please provide your full code. My guess would be that JOKE+no[0] and JOKE+no[1] produce the same key which would lead to JOKE+no[1] overrwriting JOKE+no[0].

public int[] no;
	int i;
	// Use this for initialization
	void Start () {
		
		i=2;	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	void OnGUI()
	{	
		PlayerPrefs.SetInt("No", no[0]);		
		PlayerPrefs.SetString("JOKE"+PlayerPrefs.GetInt("No"), "one");
		
		PlayerPrefs.SetInt("No", no[1]);
		PlayerPrefs.SetString("JOKE"+PlayerPrefs.GetInt("No"), "two");
          }
}

Ok so this code is a bit different but this is what happends: you save int no[0] with key “No”, two lines later you overwrite that value with int no[1].
Its important to understand that if you want to save multiple values you need multiple and unique keys. (also if no[0] and no[1] are the same value, this example would fail too)

so, do you know any other way to do this function?

Start simple with something like:

void Start()
{
PlayerPrefs.SetString("JOKE_ONE", "one");
PlayerPrefs.SetString("JOKE_TWO", "two");

Debug.Log(PlayerPrefs.GetString("JOKE_ONE"));
Debug.Log(PlayerPrefs.GetString("JOKE_TWO"));
}

And build from there.

but i want to save the more than 100 data in this… so i need array function for this…

In this script i try to save the data when my toggle button is enable. if toggle is dis able that data should not save. This is my concept.

Here is the script:

public string[] lables;
	public bool[] selects;
	public int[] no;
	public GUIStyle lablestyle;
	
	public string[] saveditem;
	static int save;
	// Use this for initialization
	void Start () {
		
		save = 1;
		saveditem = new string[save];
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	void OnGUI()
	{	
		for(int i =0; i < lables.Length-1; i++)
		{
			selects[i] = GUI.Toggle(new Rect(100, (30 * i) + 100, 20, 20), selects[i], "");
		}
				
		if(GUI.Button(new Rect(130, 100, 100,30), "Press"))
		{
			save++;
			saveditem = new string[save];
		}
		saveditem = new string[save];
		
		if(selects[0].Equals(true))
		{
			PlayerPrefs.SetString("Playre"+saveditem[save], lables[0].ToString());
			print(lables[0].ToString());
			save++;			
		}
		
		if(selects[1].Equals(true))
		{
			PlayerPrefs.SetString("Playre"+saveditem[save], lables[0].ToString());
			print(lables[0].ToString());
			save++;			
		}
		
		if(selects[2].Equals(true))
		{
			PlayerPrefs.SetString("Playre"+saveditem[save], lables[0].ToString());
			print(lables[0].ToString());
			save++;			
		}
		
		
		
	}

try this: http://wiki.unity3d.com/index.php/ArrayPrefs2

but i am using the toggle button for select the each line… then how it is possible?

Why dont you use another for loop?