[SOLVED]
I have CSV file filled with data that I read in a script and store in a dynamic array.
I’m having trouble with a method (getNextTrial) where I can go to the next line of data in the list and may extract to change the weather or scene in my game for example.
public class Trial
{
public int TrialNum;
public string status;
public string weather;
public int time;
public int duration;
public string scene;
public string displayType;
public string InputType;
}
public class FollowTrial : MonoBehaviour
{
public static FollowTrial instance;
public string path;
public static class ExpTrials {
private static List<Trial> trialList;
private static int counter;
private static Trial t;
public class ReadCSV : MonoBehaviour //reads data and populates list
{
public static List<Trial> ParseFromString(string file_contents)
{
//List<Trial> Trials = new List<Trial>();
string[] row = file_contents.Split('\n');
for (int i = 1; i < row.Length; i++)
{
string[] column = row[i].Split(',');
Trial t = new Trial();
int.TryParse(column[0], out t.TrialNum);
t.status = column[1];
t.weather = column[2];
int.TryParse(column[3], out t.time);
int.TryParse(column[4], out t.duration);
t.scene = column[5];
t.displayType = column[6];
t.InputType = column[7];
trialList.Add(t);
}
counter = 0;
return trialList;
}
}
public static Trial getNextTrial(List<Trial> t)
{
t = trialList[counter] ;// get trial from list and store at t
trialList.RemoveAt(counter); //remove trial from list
counter++;
return t;
}
Thank you in advanced.