Choosing condition files based on trial number: unknown resource error

OS (e.g. Win10): macOS Monterey
PsychoPy version (e.g. 1.84.x): 2022.2.5

**What are you trying to achieve?:**I have 5 different condition files. One those five, “Conditions_x.xlsx”. The other four are “Conditions_y_1”, “Conditions_y_2”, “…3” and “…4”. So for each participant I need one trial to be picked from the “x” file (this file is the same for all participants), and the next from one of the four “y” files, based one the participant number, assigned with Morys-Carter “Participant IDs for Pavlovia” method.

What did you try to make it work?:
In other experiments where I needed to assign only four files based on participant number, it always worked to write this in the Begin Experiment tab of a code component

and then to specify $"Conditions_" + nCond + ".xlsx" in the loop around the trial routine.

In this case, I tried modifying that approach accordingly, by creating the “typeCond” variable in the Begin Routine tab and assign different value to it based on the current trial being odd or even

and then this in the loop window

What specifically went wrong when you tried that?:
I need to run the experiment online through pavlovia, but it did not work locally either. The error displayed on pavlovia is

I am not a python expert but it seems the problem is typeCond not being defined. I thought it might be because of how I accessed the trial number. I tried different methods with no luck.
If I define it in Begin Experiment with an empty or fake string like typeCond=“hello” the error stays the same only with “Conditions_hello” which of course does not exist, meaning that it does not get reassigned with the Begin routine code.

Stuck on this for quite a while now, any idea is appreciated! Apologies for anything wrong with this post, it’s my first.


the last error message tells you that your if-construction does not work. :wink: You need to define the condition-file before the trials-loop starts. Insert a routine before the trials-routine and set the condition-file there.

Best wishes Jens

Hi! Thank you for your response.

To make sure I understand correctly, how should I define the condition files in the new code component before the trials routine? If I do it in the same way, just moving the code component back a routine, trials.thisN will not be inside the correct routine.

I tried some variations, the closer I got was, in a code component in the new routine, in Begin experiment:

if nCond == '0':
    nCond = 4

shape = 2

xCond = "Conditions_x.xslx"
yCond = "Conditions_y_" + nCond + ".xlsx" ```

then in the Begin routine tab of the code component in the trials routine:
```if trials.thisN % 2 == 0:
    typeCond = xCond
    typeCond = yCond

and then the Conditions field in the loop window set to $typeCond .

This way, it gives me a ReferenceError saying that a variable controlling the position of one of my stimuli is not defined. I define it within the condition files.


There is type-conflict in your if-construction

if nCond == '0':
    nCond = 4

The first line tests if nCond is string with the value of 0. The second line assigns the integer 4 to nCond changing the type of the variable to integer from string. Actually, this should throw an error

TypeError: can only concatenate str (not “int”) to str


So, simply use change

nCond = '4'


yCond = 'Condition_y_' + str(nCond) + '.xlsx'

Regarding the reference error. Either there is a typo, you are using the variable name twice, or the variable is being used before it is known to the program.

Best wishes Jens