Error when importing conditions in nested loops

URL of experiment: Pavlovia (or Sign in · GitLab if that’s more helpful)

Description of the problem:

In case it’s helpful, I am trying to create a PsychoPy/PsychoJs version of this experiment: OSF | Feng, S., D’Mello, S., & Graesser, A. C. (2013). Wiki

The experiment runs beautifully in PsychoPy, but I am having trouble getting it to run in Pavlovia. I seem to basically have the same problem as reported on Psychojs - Inner Loop pattern - #8 by rrennert14 and Error When importing condition: extension currently not supported.

In PsychoPy Builder my experiment looks like this:

Briefly, my experiment contains multiple nested loops:

  • I have an outer loop (Choose_Set) that loads a condition file SetCondition.csv. This condition file contains a column passage_condition, listing the rows Set1_Passages.csv and Set2_Passages.csv
  • The next loop “inward” (AllPassages) then calls $passage_condition as condition file and should thus call either Set1_Passages.csv or Set2_Passages.csv. These .csv files in turn contain the columns passage_list and comprehension_list which list further .csv files associated with the different passages.
  • These different passages are called in loops even further “inward” (passage_loop and comprehension_loop) which call $passage_list and $comprehension_list respectively which contain the actual variables called in the routines Sentence and Comprehension.

As reported before, Pavlovia appears to only import the conditions file in the outer loop and does not load the condition files in the inner loops, which means I get lots of 'undefined" conditions. I am currently completely stuck on how to to resolve this.

The javascript console gives the following error:

I have tried creating dummy loops as suggested in Error When importing condition: extension currently not supported - #5 by Francesco_Poli, which not only made the experiment somewhat unwieldy/unelegant (given the 20 or so .csv files in total), but also did not work.

I suppose my only option is to code this. However, given my unfamiliarity with both python and javascript, I could really use some pointers (or perhaps, dare I say it, an example experiment) of where to start or how to approach this.

Any help would be very gratefully received.

Best wishes,

Bianca

1 Like

Same problem with version 2021.1.3: conditions file resourced in an inner (trials) loop seems to be found, but its single variable is “undefined”. Yet the same experiment structure, defining the conditions file in the same way, for an earlier experiment running with version 2020.1.3, and even using the same conditions file, can use its variable; it’s defined.

Are you getting the same error “when importing condition X” where X is the first letter of your conditions file. If so, then the issue looks like [0] is being used on a string that you thought was a list.

Actually, no, I’m not getting that error. The conditions file appears to be found/loaded; at least no error message explicitly refers to an import error. There is only the usual warning about “seed” being undefined, with no subsequent error message about importing the file. It is only when I try to use the file’s one and only variable that its value is said to be “undefined”. So, assuming that I should get an error message if the file isn’t found, or there was some “import error”, I suppose the issue is different to the one raised above apart from ending up, as this earlier post noted, ending up with “undefined conditions”.
Trying to print the contents of the “trials” object for thisIndex seems to indicate–as below–that the variable is indeed found, with a defined value (in this case, 0), but in the next line, when I try to use the variable (here, just to print it), it’s given as “undefined”. (Other “prints” here show the file path ahead of and within the trial.). This is all based on auto-translation to JS from Python, with no problem at all running this in PsychoPy.

image

Having a column title undefined is indicative of it being defined twice. Try changing the name of the variable.

I’m now wondering based on the double entry in the log whether you have TARGET as a column in both outer loop and inner loop spreadsheets

Not quite - but your comment led me to what was going on, and to the following generalisation:

You can modify the value of variable imported from a conditions file in PsychoPy without issue, but if you do so in PsychoJS, this will cause the variable to be automatically defined without a value in the script, and so undefined when you try to use it.

So I was modifying my TARGET variable, read in from the conditions file, depending on a particular condition; specifically, to swap 0 to 1 and v/v.
TARGET = abs(TARGET - 1)

This left TARGET still usable (defined) in PsychoPy, but in PsychoJS, this causes the script that gets built to add the line (outside any loop or function):
var TARGET;

So when I get to using TARGET, it is no longer defined for the value read in from the conditions file----at least in PsychoJS; in PsychoPy, without imposing this initial declaration, there’s no issue.

Changing the value of the modification, above, to thisTARGET, and always using that instead of TARGET, now gets it all going (for now).

Is this a bug–incompatibility between what you can do in PsychoPy but not PsychoJS?

Thanks for your pointer about there being a conflict like this at the root of the problem.

1 Like

Thanks. I hadn’t realised you could modify the value locally (because for the past year I’ve been testing everything online).

I’ll add this to my crib sheet.

I suppose this could be solved–no incompatibility on this basis between PsychoJS and PsychoPy–if all the “auto-declarations” of variables in the .js script were made as early as possible; at least ahead of any TrialHandler read ins of conditions files. Because this issue only came up here because I made the modification to the conditions-file variable per trial, and so the declaration came just before “trialRoutineBegin”, well after “trialsLoopBegin” when the conditions file is read. So the declaration clobbered (undefined) the value from the conditions file.
EDIT: No, that’s probably not right. I just suppose somehow trialsLoopBegin is called before the variables are declared.

I cant see it in the crib sheet? I cant seem to use a variable in the conditions box of a loop to import a csv ( e.g., $csv_to_read). Used to work last year.

1 Like

There’s a rule (with exceptions) that if the field has a $ after its name then you don’t put a dollar in the field itself.

So, try without the $

I think I have a similar issue with my “Hello world” error, as I try to split a variable from my conditions file (a sentence into words). However, I couldn’t find it in the crib shit for some reason.