0
\$\begingroup\$

I'm trying to fill a dropdown with a lis,t if some input is correct.

now when trying to create the list from a text file (to save the program) i should split the line on a comma so i have 3 settings for one asset: For ex asset1,colour,used,broken. the list should show the asset if the item is broken (0 is not broken, 1 is broken).

 public string[,,,] UsedAssetList;


string[] lines = System.IO.File.ReadAllLines(@"" + Application.persistentDataPath + "/assetlist.txt");
    cmbAssetNumber.ClearOptions();
    for (int i = 0; i < lines.GetLength(0); i++)
    {

        UsedAssetList = ***lines[i].Split(',')***;
        if (UsedAssetList[i,0,0,1] == "1")
        {
            list = new Dropdown.OptionData(UsedAssetList[i,0,0,0]);
        cmbAssetNumber.GetComponent<Dropdown>().options.Add(list);
        }
    }

The lines[i].Split(',')gives me the error:

Error   CS0029  Cannot implicitly convert type 'string[]' to 'string[*,*,*,*]'  

I think everything is on point, except the filling of my list. any idea on how i can get this right?

EDIT: I was thinking the list should look like this: {{"asset1","Gold","1","0"},{"asset2","Green","0","1"} , ... }

EDIT: While the text file looks like:

asset1,Gold,1,0

asset2,Green,0,1

...
\$\endgroup\$
0

1 Answer 1

1
\$\begingroup\$

Found a way to fill the dropdown with the needed info: Using a mulitdimensional array was not needed.

my code to get it working:

public string[] UsedAssetList;
void ReloadDropdown()
{
    string[] lines = System.IO.File.ReadAllLines(@"" + Application.persistentDataPath + "/assetlist.txt");
    cmbAssetNumber.ClearOptions();
    for (int i = 0; i < lines.GetLength(0); i++)
    {
        UsedAssetList =  lines[i].Split(',');

      if (UsedAssetList[3] == "1")
       {
            list = new Dropdown.OptionData(UsedAssetList[0]);
               cmbAssetNumber.GetComponent<Dropdown>().options.Add(list);
      }
    }
}
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .