Force end routine after 2 minutes

Hello everybody,

Description of the problem: I am building a stroop task via the builder for an online experiment. The subjects should run stroop trials for exactly 10 minutes. The trials should be divided into 5 blocks of 2 minutes each. I want to interrupt the trials after exactly 2 minutes to ask some state questions but I am not sure how I can handle this. I appreciate every answer and thank you in advance!
Best regards

Hi @Lykanon, there is a way to do this using clocks. However, to end a loop is a bit of a hack, until PsychoPy 3.1.0 is released in the next week or so. Ending the loop on command has been fixed in the next release, but for now you have to end all trials in the loop when your condition is met, which will finish the loop without presenting further stim.

First, you need to create a nested loop structure that controls your inner loop of trials. In the outerloop, you will have your questions that appear after two minutes. In the outerloop, you need a code component to create your clock. In the relevant tabs:

// Begin Experiment
// Create your clock
loopClock = new util.Clock();

// End Routine
// Reset your clock
loopClock.reset();

In your main loop of trials, you need to check whether the value of the clock exceeds your time allowance, and you check this in a code component on every frame.

if (loopClock.getTime() > 120) {  // 120 seconds
      continueRoutine = false;
      }

This will end all trials left in the loop, and then you will progress on to your questions in the outer loop. Then, when the questions are complete, the outerloop resets the clock and you start again. Here is a working example (only works in JS, so you need to create a project on Pavlovia to run this example) clockControl.psyexp (11.1 KB)

1 Like

Hi @dvbridges ,

thank you very very much for your quick answer! I implemented your suggestions in my experiments and it works.

Have a nice day and best regards