Loop picking one variable from a nested loop

Hi,

I am trying to build an experiment with PsychoPy as I am still kind of new to programming I am trying to this via the builder.

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): 2020.2.4
Standard Standalone? (y/n) n If not then what?:
What are you trying to achieve?:

I want to build an experiment in which two pictures are presented. 1 picture shows a person with an emotional expression and the other person should always have a neutral expression. I want the emotional picture to be a specific picture which is listed in my conditions file. The second neutral picture should be any picture out of a second conditions file (so I kind of thought of it like a nested list in e-prime). My goal is to pick 1 random picture of the list with the neutral expressions and present it together with the specific emotional expression.

What did you try to make it work?:

So, I created 2 excel sheets. One for the outer loop which contains a column with the filenames of the emotional expressions and in a second column I tried to refer to a second excel sheet with contains 10 neutral expressions and want to pick one randomly out of this second excel list.

What specifically went wrong when you tried that?:

Well actually the experiment did not even start it crashes immediatly and does not give me any error messages. May be there is a certain way to achieve what I am think about, but I guess I am not experienced enough.

Thank you in advance I really hope you can help me!!

Having a loop within a loop should work, could you share your .psyexp file?

The not showing errors bug was fixed in 2020.2.5 so if you upgrade your version then you should get error messages at least - or if you make sure your preferences are set so that Builder, Coder and Runner open when PsychoPy starts and then don’t close the Runner window it should also fix the bug.

Hi,

sorry for the late response I was sick in bed last week. So I kind of managed a way to do what I intended in the beginning but I still think this is not the most elegant way to do this.
I managed to have a loop within a loop. My outer loop manages the different excel files. Within the excel files I have the pictures I want to show. The only thing that is still bothering me is that in those excel files I have 9 lines with the same emotional expression of just 1 person paired with a neutral expression of a different person.
(e.g. happy_man01.jpg | neutral_man02.jpg
happy_man01.jpg | neutral_man03.jpg and so on)
My wish would be to have only 1 line with an emotional expression and a second column which refers to an excel sheet with all the neutral expressions and it randomly picks one of it.
(e.g. happy_man01.jpg | [neutralimg]
happy_man02.jpg | [neutralimg])

Is it possible to do something like this in PsychoPy? I know it is possible in e-prime it would really make things a lot more easy for me!

Thank you in advance! If this isn’t understandable I can share my programfile.

Best,
Robert

This should be possible, yes! If you put a list of filenames in one cell separated by a “delimiter” (usually a comma), you can then split this string into a list using a line of Python code:

neutralList = neutralImgs.split(",")

and then use the random functions provided with psychopy to choose one of these at random each trial. For example, you could set your image value to be:

$neutralList[randint(len(neutralList))]

and set its update value to “Update each repeat”

Thank you, this sounds very promising! I will try it!
One more question: It sounds like it will pick one of the neutral images randomly, so repitions are possible, right? Is it also possible that it first runs all the pictures and when each picture was presented once repitions follow?

For that I think you’re better off using a loop within a loop! The advantage of a loop rather than doing it manually with delimiters in cells is that loops have this kind of behaviour built in.