- Home /
ArrayPrefs 2 (PlayerPrefs X) Question
Is there a way I could do a HasKey function using PlayerPrefsX? The reason I ask this is because when there is no value stored in a key for an array, it returns an empty array. This is alright, but I have some 2D and 3D arrays I need to use and when the game hasn't been saved, it returns them as 1D arrays. If there was a HasKey function I would be able to prevent this... Any ideas?
Thanks!- YA
Answer by Screenhog · Aug 14, 2012 at 06:14 PM
Simply use PlayerPrefs.HasKey.
PlayerPrefsX converts other types into a type that PlayerPrefs can understand. When you're saving data with PlayerPrefsX, it's converting to PlayerPrefs behind the scenes. Thus, PlayerPrefs.HasKey just works.
And yet, I still get the error thrown at me. I need a way to either make an exception and block the error, or how to Save/Load 2D arrays in PlayerPrefsX.
Is this possible?
When saving a 2D array, could you save it as a 1D array, and save another array of ints, with each int being the length of the line in the 2D array? When loading the array as a 1D array, use your array of ints to break it up into the pieces you need.
For a 3D array... I don't know.
Interesting... Well I could just as easily use the same strategy for the 3D. Last question, and you've been great thank you very much:
Can I save a variable directly as opposed to referencing a key in an array?
I would like to go
PlayerPresX.SetInt((PlayerPrefsX.GetIntArray("$$anonymous$$yArray")[2]),3);
That would find the index of the Array I loaded and save that variable. Sadly I get errors thrown at me when I try this as well. Is there another way?
Thanks- YA
No, that's not possible, and it's not really what PlayerPrefs are designed for. The only goal of PlayerPrefs is to be able to save and load from your computer's memory. The better practice would be to load your array once and save your array to an in-game variable, and then get your information from that.
I understand that. The above code is actually then saved into a variable.
$$anonymous$$y goal here is simply this: I have one set of variables. For instance: Name, $$anonymous$$oney, and, say, Level.
In my game there are 3 save slots. So I would have 3 arrays with 3 values each, representing the value assigned to each slot. So ins$$anonymous$$d of going
If Slot number == 1{ Name = Slot1Name } if SlotNumber == 2{ Name = Slot2Name } if SlotNumber == 3{ Name = slot3Name }
Ins$$anonymous$$d I can go:
Name = Names[Slot];
And yes that was all psuedo-code ;)
But what if I need to make 3 different arrays for each save slot? Then what do I do? This problem is perplexing for me and I cannot find a good solution to it. :/
Answer by DavidBrehl · Dec 24, 2017 at 08:37 PM
how the hell do i get arrayprefs 2!??!?!!??
first result if you google "arrayprefs 2" http://wiki.unity3d.com/index.php/ArrayPrefs2
Your answer
Follow this Question
Related Questions
How do you save GameObject[]? 1 Answer
How to create a save and load game proccess like SCP: Containment Breach? 0 Answers
Save Values On Closing of Game 1 Answer
Create GUI based on an array 2 Answers
Saving Location in Unity 1 Answer