Conditions for section to end

Hello!

I would like to make a section end when the participant gets 8 correct trial responses in a row. If this doesn’t happen, the section should end after a certain amount of trials. Is there a way to do this?

Thanks,
Mary

Hi.

In code you need a counter which increments on a correct response and resets to 0 on an incorrect response.

If score >= 8: trials.finished = True

The maximum number of trials should be set via nReps or checking trials.thisN

Thank you so much for replying. I have zero coding experience. What you’re saying make sense I’m just unsure how to do it in this programme. Do I just type this into the PsychoPy Coder? In the part that says Shell?

If score >= 8: trials.finished = True

Add a code component to the last routine within your loop (which I am assuming is called trials).

Add score=0 to Begin Experiment and the following code to the End Routine tab.

score+=key_resp.corr
thisExp.addData('Score',score)
if score >= 8: 
     trials.finished = True

key_resp is the name of your keyboard component. If it doesn’t work, have a look at the data file to see what’s happening to the Score column.

1 Like

Thank you so much! Just wanted to ask, if it’s the whole loop I want to end, instead of the trial, how do I change the last part of the code for it?
Example:
I have a word to grab the participant’s attention, ‘ready’ for half a second, then I have an audio component, then I have the keyboard response as all the audio files are different lengths. So really I should code fore the loop to end, not just the trial. Do I just type this instead:

learning_trials.finished = True

Note: ‘learning_trials’ is the name of the loop.