- Home /
How to save an array to PlayerPrefs?
I know about PlayerPrefsX (http://wiki.unity3d.com/index.php/ArrayPrefs2) but I don't know how to save something like this to it:
var storage = new Array("box", "table", "chair");
Whenever I try PlayerPrefsX.SetStringArray, I get errors. I tried just PlayerPrefsX.SetArray, but that didn't work either. Is there a way to save an array like this?
"I get errors" is remarkably uninformative. Please be a little more specific?
Alternatively, you can use serialization ins$$anonymous$$d of PlayerPrefs to store your data. Here is a good tutorial on save/loading in Unity: http://gamedevelopment.tutsplus.com/tutorials/how-to-save-and-load-your-players-progress-in-unity--cms-20934
(in C# rather than javascript, but you should use c# ins$$anonymous$$d of javascript anyway. :P I don't know how serialization works in javascript. )
The errors are "The best overload method" for SetStringArray and "$$anonymous$$issing Exception" for SetArray
Come on... please copy paste the errors and the lines that cause them here. A doctor can't help you if you go to him and just say "it hurts".
Assets/Custom Assets/Scripts/Stats.js(69,36): BCE0017: The best overload for the method 'PlayerPrefsX.SetStringArray(String, String[])' is not compatible with the argument list '(String, Array)'. That's for the SetStringArray $$anonymous$$issing$$anonymous$$ethodException: PlayerPrefsX.SetArray Boo.Lang.Runtime.DynamicDispatching.$$anonymous$$ethodDispatcherFactory.ProduceExtensionDispatcher () Boo.Lang.Runtime.DynamicDispatching.$$anonymous$$ethodDispatcherFactory.Create () Boo.Lang.Runtime.RuntimeServices.DoCreate$$anonymous$$ethodDispatcher (System.Object target, System.Type targetType, System.String name, System.Object[] args) Boo.Lang.Runtime.RuntimeServices.Create$$anonymous$$ethodDispatcher (System.Object target, System.String name, System.Object[] args) Boo.Lang.Runtime.RuntimeServices+c_AnonStorey15.m_9 () That's for SetArray
Answer by sprawww · Mar 28, 2015 at 12:06 AM
I don't really know JS/US, but this should be correct:
var storage = ["box", "table", "chair"];
PlayerPrefsX.SetStringArray ("Storage", storage);
Just to be safe, the C# Version:
var storage = new string[] { "box", "table", "chair" };
PlayerPrefsX.SetStringArray ("Storage", storage);
Thank you so much! The JavaScript works perfect!
you have the class in the link. scroll little bit down you will see it - there is both js and c#.
Your answer
Follow this Question
Related Questions
Saving Array Objects in Android. 0 Answers
PlayerPrefsX plugin error when build for windows store 3 Answers
How do I save a three dimensional array? 1 Answer
bool array to playerprefs 1 Answer
assigning arrays with for in 1 Answer