psychopy.org | Reference | Downloads | Github

Loops + Sounds + Groups

If this template helps then use it. If not then just delete and start from scratch.

OS (Win10):
PsychoPy version (v2021.2.3):

I am trying to do four different things, that would add themselves to my initial experiment, made of multiple loops.

1) I have sound stimuli that the participant need to repeat. Stimuli are displayed sequentialy.
If participant don’t hear the stimulus (because of an external reason for instance), I want them to be able to play them again (with no limited number of times).
I tried to add a loop with a code (shown below) with the conditions being “doNew” but this does not work because Psychopy does not recognize the condition and I don’t know how to fix the problem : do I have to create a xlsx file ? If so, what should I write in it ?

Code :
if(Bilo_reponses.keys==‘space’):
doNew=1
else:
doNew=0

2) I want to add stop criterion to my inside loops, that is to say that if the participant gets 4 consicutive zeros, the trial would end.
I tried to add this code to my components but this does not seem to be exact :

trials.finished=True
if key_resp_celf.keys is not None and len(key_resp_celf.keys)>4 :
trials.finished=1

3) I added a list of Groups as Experiment settings and more specificaly in Experiment info. I want the trials to be different, depending on the group the participant is in and if possible, I’d like to randomize the order of the selected trials.
For example, if I choose the group “MS”, I want the participant to access trial 1;3; 5 and more specificaly only the items 1;5;6;7;8;9;…;end within the trial 3.

I tried to add a .xlsx file “chooseGroup” with $cond_file having the list of trials depending on the group and then added a general loop taking all my trials together, but that does not seem to be sufficient.

4) I want the participant to be able to lower the Psychopy window and do something else in between two trials. Do I have to add a specific code or should I just not selct “Full-scree window” in the Experiment settings ?

Thank you very much for your help. Tell me if I forgot to tell anything or if I am not clear within my explanations.
I can’t wait to read you.

Olivia

Hi Olivia,

1) I have sound stimuli that the participant need to repeat. Stimuli are displayed sequentialy.
If participant don’t hear the stimulus (because of an external reason for instance), I want them to be able to play them again (with no limited number of times).

I believe that you need nested loops - this demo allows repeats of sound using the approach you suggest, but you would need another loop around this loop, and that loop would be where you feed in yous trials list spreadsheet.
replaySound.psyexp (10.5 KB)

2) I want to add stop criterion to my inside loops, that is to say that if the participant gets 4 consicutive zeros, the trial would end.

Your code is close, we would need to understand your trial structure better to be specific here. You want something like this (assuming that “zeros” refer to incorrect responses"

#Begin experiment tab
corr_tracker = []

# End routine tab
corr_tracker.append(key_resp_celf.corr) # will add a 1 to the list if correct or a 0 if incorrect 
# Assuming "zeros" refers to making an incorrect response
if len(corr_tracker) > 4:# if more than 4 responses have been made
    if sum(corr_tracker[-4:]) == 0: # the last 4 responses were 0
        trials.finished=True # end the trials loop

3) I added a list of Groups as Experiment settings and more specificaly in Experiment info. I want the trials to be different, depending on the group the participant is in and if possible, I’d like to randomize the order of the selected trials.
For this I would recommend taking a look at this tutorial on how to complete this.

4) I want the participant to be able to lower the Psychopy window and do something else in between two trials. Do I have to add a specific code or should I just not selct “Full-scree window” in the Experiment settings ?

Yes - just ensure full screen is set to false in experiment settings.

Hope this helps!
Becca

Thank you so much for your answer ! It really helped !!

I am sorry to bother you again : I still have a problem with my repetition loop.

1) I have sound stimuli that the participant need to repeat. Stimuli are displayed sequentialy.
If participant don’t hear the stimulus (because of an external reason for instance), I want them to be able to play them again (with no limited number of times).

This is what my loops look like.
The code I have is

Begin Routine:
if Bilo_reponses.keys == ‘space’:
trials_6.finished = True

End Routine:
if Bilo_reponses.keys == ‘space’:
trials_5.finished = True

The settings of my outer loop are:


And the settings of my inner loop are the same (I can’t put the picture here)

=> So now, when I press ‘space’, it starts over the trials_6 loop.
And I want the condition of this loop to move forward in the same time as the condition of my trials_5 loop, so that when element from row 5 is played, it can be played again when I press ‘space’.

I hope I am clear in my explanations. I read the replaySound.psyexp but they only have one element to replay and this is not my case.

Thank you again for your help !