| Reference | Downloads | Github

Start new trial with Keypress

Hi all,

I am trying to add the possibility to start a new trial before the entire loop has finished.
Participants hear two segments of music and then are asked if the two segments are different (in the ‘discern’ Routine. If they answer ‘y’ (Yes), I want them to continue to MS3, but if they answer ‘n’ (No), I would like them to start a new trial.

I have tried inserting various lines of code into the End Routine section of the ‘continue1_3’ code component, but have not had any success. This is my latest attempt:

if key_discern.keys == ['n']:
    currentLoop.finished = True

Also, just in case anyone thinks of this as well, I have already turned off the ‘force end of routine’ button in my key_discern dialog box.

Hi Kevin, you’re thinking about this from the wrong direction. You don’t actually want to terminate the loop: that would stop all further trials. What you want is for the loop to continue on without interruption, but make execution of the MS3 routine contingent on the response on the discern routine.

So you do want ‘force end of routine’ button in your discern routine. Then insert a code component in the MS3 routine, and put something like this in the Begin routine tab:

# don't run this routine if the subject answered no:
if 'n' in key_discern.keys:
    continueRoutine = False

1 Like