Select a specific row of the conditions file inside a loop

Hi all,

I am using PsychoPy v2022.2.4 on macOS Ventura Catalina 10.15.7 (19H2026).

In my experiment, the participant has to study a concept and its definition, and can choose between three options: (1) re-read the concept and definition, (2) try to retrieve the definition by looking at the concept, and (3) rule out further studying that concept and move on to the next one. I have already managed it using several nested loops, but now I am faced with the difficulty of how to show the participant the following concept once once you have chosen the third option, that of discarding. I understand that I must include a small piece of code where a variable is created that allows me to increment it in each iteration of the loop, and that this variable should then be used to select the row of the conditions file that I use to present the stimuli (concepts and definitions ). I have tried it in the following way:

(1) in the code interface I have created a variable (it is called num_concept) at the “beginning of the experiment”, and I have given it the value of zero.

(2) I have increased this value by one in the “end of routine” part, with the following statement: concept_num+1.

(3) I have used this variable to select the row within the conditions file using “$num_concept”.

When I run the layout it gives me the following error:

File “/Users/mariadolores/Dropbox/doctorado UJA/psychopy/primer articulo/primer experimento/fase_aprendizaje/pruebas/contador_lastrun.py”, line 114, in

trialList=data.importConditions(‘conditions_2.csv’, selection=num_concept),

File “/Applications/PsychoPy.app/Contents/Resources/lib/python3.8/psychopy/data/utils.py”, line 457, in importConditions

elif len(selection) > 0:

TypeError: object of type ‘int’ has no len()

A greeting and thank you very much for the attention,
Miguel

selection is not a list; it’s an int. Why are you checking its length?
Isn’t num_concept just a number?

Instead of typing:

elif len(selection) > 0:

Try:

elif selection > 0:

Hello Chen, thanks for the answer and for your time, however I am not very clear what you mean, my knowledge in PsychoPy is limited, so I apologize if I say something stupid. The num_concept variable is a number, and I want to use it as a counter (which will increment progressively) to tell the loop which row of the file to select. I don’t want to know the length of that variable.

This is what I’m doing:

Captura de pantalla 2023-03-10 a las 7.26.32

Hello,

I might be missing something but isn’t num_concepto always 1? You increase its value by 1 when p, r or d is being pressed. So you could just write 1 into Selected rows or take it out of the ifelif-construction.

Best wishes Jens

Hello JensBoelte,
thanks for the answer, you are right that the code is poorly written but I don’t quite understand what you mean. If I put a 1 in selected rows, won’t the first value of the variable always appear? My intention is for each of the values to appear sequentially each time the participant enters the loop. In the event that I take it out of the ifelif construction, where should I write it to achieve the goal that I have mentioned before? Thank you very much for the help

Hello Miguel

sorry, not clear enough. You set num_concepto to 0 at the beginning of the experiment and you increase it by 1 at the end of each routine. You use num_concepto in Selected rows. AFAIK, you need to tell PsychoPy all rows that you want to select at the first iteration of the routine. I don’t think that you can iterate the row by increasing the value inserted in Selected rows. You might want to read this to get a better understanding of loops:

https://www.psychopy.org/builder/flow.html#loops

I add a simple toy experiment in which the concept is repeated when pressing 1 for maximally 100-times, another text is shown once when pressing 2 and another text is shown when pressing 3.

PressedThree.psyexp (18.1 KB)
Concept.xlsx (8.4 KB)

I am not certain whether this can be adapted to your needs but I did not quite understood your experiment description.

Best wishes Jens

Hi Jens Boelte,
I am very thankfull for your help. I’m going to read the entry about the loops and “play” a bit with the flaw that you send me to see if I can find the solution,
Thank you