Save Array in PlayerPrefs

Dear Community,

i want to save an array with PlayerPrefs and im using the function, find in the link below:

http://wiki.unity3d.com/index.php/ArrayPrefs2#JavaScript_-_PlayerPrefsX.js

In my save function i got this:

for (var value:String in bezugQuestlogArray.quest)
	{
	PlayerPrefsX.SetStringArray("Questlog", bezugQuestlogArray.quest);
	}

In my debugger appears that error:
The best overload for the method ‘PlayerPrefsX.SetStringArray(String, String[ ])’ is not compatible with the argument list ‘(String, Array)’.

I dont know whats that mean, hope you can help me:(

Greetings
Vanessa

You are separating the array into individual strings and giving it to a function that is asking for an array.

bezugQuestlogArray.quest is an Array, not a string[ ]
http://wiki.unity3d.com/index.php?title=Which_Kind_Of_Array_Or_Collection_Should_I_Use%3F

Your code won’t work, since you’re iterating through the array, but attempting to save the array every iteration and doing nothing with the “value” variable. You should get rid of the for loop. Also, never use the JS Array class. It’s obsolete and ArrayPrefs will not work with it.

–Eric

Thanks for your answers!

What i need is a kind of this, right?

var quest= ["Quest1blablabla", "Quest2blablabla", "Quest3blablabla"]

Im currently pushing my questtext in my array everytime the player accepts a quest:

quest.push(mandredQuestApfel);

How can i change this to work with the needed string[ ] type, or is there another way to save my current quest array in player prefs?
This is really confusing :face_with_spiral_eyes:

Greetings
Vanessa

You could use a generic List, and then convert it to an array using ToArray before saving, and convert the array to a List when loading by passing the array into the constructor. e.g., “var foo = new List.(PlayerPrefsX.GetStringArray(“MyArray”));”

–Eric