immersivecognition / unity-experiment-framework

UXF - Framework for creating human behaviour experiments in Unity
https://immersivecognition.github.io/unity-experiment-framework/
MIT License
221 stars 43 forks source link

UXFDataTable.AddCompleteRow() method could not detect same string (not a string variable) when declaring headers for custom data table #138

Closed allen6chen closed 2 years ago

allen6chen commented 2 years ago

Hi, when I try to call a new UXFDataTable, I directly use string to represent the headers of the data table and . my code:

//The following code is in **global vairable:**
Line 1: UXFDataTable continuousDataTable = new UXFDataTable("Exact moment of pressing key","Pressed key");
Line 2: UXFDataRow dataTableResponse = new UXFDataRow();
Line 3: private float exact_moment;
Line 4: private string keycode;

//The following code is in **a method**:
Line 5: dataTableResponse.Add(("Exact moment of pressing key", exact_moment));
Line 6: dataTableResponse.Add(("Pressed key", keycode));
Line 7: continuousDataTable.AddCompleteRow(dataTableResponse);

Different from your example code:

//all code is in **one method**
Line 1: string exampleQuestion1 = "How difficult was the task";
Line 2: string exampleResponse1 = "Easy!";
string exampleQuestion2 = "How are you feeling today on a scale of 1-7";
int exampleResponse2 = 6;
var headers = new string[]{ exampleQuestion1,  exampleQuestion2 };
var surveyData = new UXF.UXFDataTable(headers); 
one row for the response (only 1 participant here!)
var surveyResponse = new UXF.UXFDataRow();
Line 9: surveyResponse.Add((exampleQuestion1, exampleResponse1));
surveyResponse.Add((exampleQuestion2, exampleResponse2));
surveyData.AddCompleteRow(surveyResponse);

https://github.com/immersivecognition/unity-experiment-framework/wiki/Collect-Custom-Data

But it seems like when I try to use UXF.UXFDataTable.AddCompleteRow(), the console will produce the following error:

InvalidOperationException: The row does not contain values for the same columns as the columns in the table!

I'm guessing it's because I didn't assign the headers as the string variable like in your example (Line 1 and Line 9), which UXF couldnt compare two same string like line 1 and line 5.

Since I want to keep acccessing the already created table to update while I run the experiment, do you know is there any way that I can do that?

Thank you in advance :)

jackbrookes commented 2 years ago

The error message should show you the headers in the Row vs in your Table. Then you can see where the discrepancy is.

But looking at your code, probably you want to add a new row each time? In that case, create a new row:


//The following code is in **global vairable:**
Line 1: UXFDataTable continuousDataTable = new UXFDataTable("Exact moment of pressing key","Pressed key");
Line 2: UXFDataRow dataTableResponse = new UXFDataRow(); // this is not needed...
Line 3: private float exact_moment;
Line 4: private string keycode;

//The following code is in **a method**:
Line X: UXFDataRow dataTableResponse = new UXFDataRow(); // <-- make new row
Line 5: dataTableResponse.Add(("Exact moment of pressing key", exact_moment));
Line 6: dataTableResponse.Add(("Pressed key", keycode));
Line 7: continuousDataTable.AddCompleteRow(dataTableResponse);
``
allen6chen commented 2 years ago

Thank you so much for the response Jack