Modify PlayerPrefsX.SetStringArray to accept 2D Array??

Hello…Does anyone know how to modify PPX.SetStringArray so that it saves the data of a 2D Array? I realllly need help with this…Or is there another technique I could use to save my data?

I store data in an 2D Array:

    public static string[ ][ ] Inventory = {
        new string[ ] {null,null,null,null,null},
        new string[ ] {null,null,null,null,null},
        new string[ ] {null,null,null,null,null},
        //etc..
   };

But I cannot figure out how to save it! The only thing that comes close to saving my data is:

    for (int i = 0; i < 3; i++)
    {
         for (int j = 0; j < 5; j++)
         {
       
             PlayerPrefsX.SetStringArray("CharChoice" + PlayerPrefs.GetString("CurrentSlot"), Inventory[i][j]);
         }
    }

But I think PlayerPrefsX.SetStringArray needs to accept a 2D Array straight up. I don’t think the iteration scheme is doing anything…

Please could someone help?

You’d have to write new functions in PlayerPrefsx to handle that. Offhand I’d guess you’d put everything into a 1D string array and use another separator character to divide each row.

–Eric

I have 8 rows, and 5 coloumns (8 categories and 5 slots for each category). Putting everything into a 1D would cosist, of perhaps:

    public static string[ ] temp = 
    { "empty", "empty", "empty", "empty", "/empty" /* 7 more times */ };
    
    private char sep = '/' // where / is the seperator?

is that the idea?

Yeah, sounds right.

–Eric

could I have a more educated example? Something to reference?

Am I still keeping my 2D Inventory array? What do I do when I reach the comma?

    public static string[ ] TEMP = {

         "empty", "empty", "empty", "empty", "empty/",
         "empty", "empty", "empty", "empty", "empty/",
         "empty", "empty", "empty", "empty", "empty/",
         "empty", "empty", "empty", "empty", "empty/",
         "empty", "empty", "empty", "empty", "empty/",

          //....
   };

So we get the data OUT OF THE 2D ARRAY (it is program dependent) INTO THE 1D:

      private char sep = '/';    

      for (int i = 0; i < 25; i++)
      {
             for (int j = 0; j < 5; j++)
             {
                    TEMP[i] = Inventory[i][j];
             }
      }

Then we save…

PlayerPrefsX.SetStringArray("CharChoice" + PlayerPrefs.GetString("CurrentSlot"), sep, TEMP);

Okay I am not properly transferring the contents of my array, maybe this is a better iteration scheme:

    int i = 0, j = 0, k = 0;

    while (i < 50)
    {
            if (Inventory.TEMP[i] == sep) {
                j = 0;
                k++;
            }
			
            Inventory.TEMP[i] = Inventory[k][j];
            i++;
            j++;
    }