Access Condition File variables online experiement

Hi, I need help accessing the condition file variables for an online experiment for a custom code block. For each trial of the experiment, I need to grab 10 features that are associated with the word of the trial. I was able to use data.importConditions(‘file.xls’) to grab all the data in Psychopy, and I would go through all the data to find out which “row” has the information I need. But data.importConditions(‘file.xls’) doesn’t work online on Pavlovia, I’m wondering if there’s an equivalent way of grabbing all the condition file data or a better to do this? I tried using psychoJS.experiment._trialsData, but nothing being returned. My current conditional file looks like this.

Did you find a solution? I have the same issue. I have a code component that uses data.importConditions() to load information from a CSV file. When I run it on Pavlovia, I get this error messgae " ReferenceError: data is not defined". When I look at the console from the browser inspect view, the error messages are:

ReferenceError: data is not defined
at Scheduler.experimentInit [as _currentTask] (PLW_development_04.js:127)
at Scheduler._runNextTasks (util-2020.1.js:1091)
at Scheduler._runNextTasks (util-2020.1.js:1094)
at update (util-2020.1.js:1058)

The problematic line in the javascript (line 127) is
imageNamesRel = data.importConditions(“relevantImageNames.csv”);

I think there is another post asking how to translate data.importConditions into javascript, but didn’t get an answer.

I’ve just used the method on my crib sheet successfully:


myData = data.TrialHandler(nReps=1, method='sequential', extraInfo=expInfo, originPath=-1, trialList=data.importConditions('conditions.xlsx'), seed=None, name='myData')

Access individual values using: aValue = myData.trialList[Idx]['variableName']  


myData = new TrialHandler({
psychoJS: psychoJS,
nReps: 1, method: TrialHandler.Method.SEQUENTIAL,
extraInfo: expInfo, originPath: undefined,
trialList: 'conditions.xlsx',
seed: undefined, name: 'myData'});```
1 Like

That worked! Thank you so much! Also thanks a lot for the crib sheet! It should be pinned to the top of the Online section of the forum or listed in the PsychoPy documentation page!

What is the java equivalent of:

Access individual values using: aValue = myData.trialList[Idx][‘variableName’]

That auto translates correctly – possibly just with the addition of a semi-colon.

Thanks for your quick reply. That solution doesn’t work for me. I have a condition file with a column named “presentDur”

I imported as follows:

myData = new TrialHandler({
“nReps”: 1, “method”: “sequential”,
“extraInfo”: expInfo, “originPath”: (- 1),
“trialList”: importConditions(“conditions.xlsx”),
“seed”: null, “name”: “myData”

Then I tried to get the presentDur variable as follows:

aValue = myData.trialList[1]["presentDur"];

And I got the following error:

unable to prepare trial list: unknown type: function

Your version seems to have a lot more quotes than mine.

That’s what the auto translate function in psychopy spit out, but I also tried it without the quotes and it also does not work:

  myData = new TrialHandler({
	psychoJS: psychoJS,
	nReps: 1, method: TrialHandler.Method.SEQUENTIAL,
	extraInfo: expInfo, originPath: undefined,
	trialList: 'conditions.xlsx',
	seed: undefined, name: 'myData'});

  aValue = myData.trialList[1]["presentDur"];

Although I do get a different error message:

ReferenceError: myData is not defined

Is conditions.xlsx in your html/resources folder on gitlab?

Yes, I can reference the image file addresses in the condition file no problem. But to get it to run I need to hard code the stimulus duration.

The value “pic” is a column in my condition file and it works just fine:

aValue = myData.trialList[1]["presentDur"]; //this is the error producing line
// update component parameters for each repeat

image.setImage(pic); //this also draws on the condition file but works

Maybe there’s an error in your conditions file. Please could you attach it?

BTW, you do know that .trialList[1] is asking for the second value, don’t you?

Hi, yes, I’m aware, but thanks for checking. Hopefully I’m doing something very obviously stupid. As you can see in my conditions file, the first row has a presentation time of only 1s and for testing, I wanted something longer.

conditions.xlsx (8.6 KB)

When I open the file, the cursor is in D7 which is outside the range of your variables.

I resaved with the cursor in A2 and the error is still there. The error message is:

ReferenceError: myData is not defined

Does this suggest that the entire myData variable is unavailable? If yes, where does the script draw the pic variable from?

After 50+ rounds of making and remaking little edits, I’ve gotten the following line to work:

A) aValue = presentDur;

presentDur is a direct reference to a column in my condition file and its value is accurately updating with each iteration of the trial loop. I had tried this referencing before, and it had previously not worked. I must have had an unknown typo somewhere that I’ve now gotten lucky and unknowingly corrected. The cursor save position seems irrelevant. I tried saving the cursor position at A2 vs. F6 and that did not make a difference to it running.

Despite the above line A working, the following line still does not work:

B) aValue = myData.trialList[1]["presentDur"];

It now gives a new error though:

TypeError: Cannot read property ‘1’ of undefined

The difference between line A and line B is the absolute only difference between the version of the task that works and the version that produces the above error.

For my purposes, I think that I can move forward from here. It is frustrating not being able to index into the condition file directly, but I can probably get my task programmed using the direct column referencing.

Thanks, wakecarter, very much for your quick responses in helping me troubleshoot this issue!

Do you have a loop pointing at the Excel file? The code we’ve been discussing is an alternative solution for reading spreadsheets so the issue could be that you are trying to do both.

There is a third method of reading spreadsheets which you can see in the links at the bottom of my crib sheet

That’s very helpful. How do I change the code you provided if my loop doesn’t point at an excel file but at a variable which sets the excel file based on participan’ts number? So in my case, I have this


At the beginning of the experiment, I have this:

if expInfo['participant']=='1':

UPDATE: Actually, I fixed it. But it gives only the first row of the column I specified. I want it to print the row that is active on each trial? Is it possible to do that?

Please could you show the code or component parameter that is only giving the first row?

This one:

myData = data.TrialHandler(nReps=1, method='random', extraInfo=expInfo, originPath=-1, trialList=data.importConditions(condition), seed=None, name='myData')

aValue = myData.trialList[0]['Images']