SetString error with PlayerPrefsX

Hello,

I am using the ArrayPrefs2 script from wiki (PlayerPrefsX.js). When I’m trying to save some strings in an array I get the following error.

“NullReferenceException: Object reference not set to an instance of an object
PlayerPrefsX.SetStringArray (System.String key, System.String stringArray) (at Assets/Standard Assets/Scripts/PlayerPrefsX.js:175)”

Here’s the line what I’m using:

PlayerPrefsX.SetStringArray ("Diary_text_1", diary.story_text);
  • story_text is a string array (var story_text = new String[21];) where I want to store some strings and what I want to save.

Does anyone has any idea what could be the problem here? Thanks in advance.

diary.story_text is probably wrong; see here for accessing other game objects.

I managed to solve the problem. The problem was indeed with the story_text variable, although the issue wasn’t that it couldn’t be accessed. (I was assigning some other variables to that and was trying to save those and not the actual array.)

Now I have another question. Can you tell me how can I check if a string key already exists? I would need this so if it exists only then I will load it.
Thanks.