continueRoutine = false, but routine still running without stimuli

OS (e.g. Win10): macOS 11.6
PsychoPy version (e.g. 1.84.x): 2022.2.4
Standard Standalone? (y/n) If not then what?: y
What are you trying to achieve?: skip a loop with two Routines

Dear all,

my experiment has a trial-by-trial cueing design, where participants perform one of three possible tasks depending on the instructions they received at the beginning of the trial. In one out of three tasks, participants do a partial recognition test after seeing an image. So the logic behind my design is the following:

  • if task == taskA or task == taskB, skip the test
  • if task == taskC, do the test (which consists of two Routines, one 3s and one 1s long)

Now, this should be fairly simple by setting continueRoutine on false at the beginning of each Routine, if the condition is met:

if task == ‘A’ or task == ‘B’:
continueRoutine = False

However, instead of skipping the Routine, Psychopy displays a blank screen for 4 seconds (the summed duration of the two test Routines). So it looks like the Routine is not skipped, although no stimuli are shown.

Has anyone encountered this problem before? What would you recommend to sort it out?

Thanks!

Please could you show a screenshot of your code component?

Of course!

Add print(task) to the top to check what values of task you are actually getting. Pay particular attention to spaces. I’m guessing that your other print statement isn’t showing.

It does print both the right task and the other statement.

The stimuli in “test” and “feedback” are not shown. But for some reason, I get a blank screen as long as test and feedback combined (4s), if task==‘LTM’ or task==‘STM_notest’.

Screenshot 2022-11-11 at 12.28.44

Try putting the code in Each Frame. It shouldn’t be necessary but I think there was a bug in an earlier version that required that. Is your “use version “ blank?

My “use version” was blank, now I set it on “2022.2.4”, but it didn’t change anything. I added the code in Each Frame and no luck either.

Blank is generally better. To clarify, You ARE seeing the “No test in this trial” message come up?

If so, I’m not sure why continueRoutine = False isn’t working for you but there is an alternative method that should work.

Correct, I’m seeing the “No test in this trial” message in the runner.

I have no idea why the countinueRoutine isn’t working, but the alternative method works! :slight_smile: Thank you so much.

I’ve just confirmed that continueRoutine = False does not work in 2022.2.x offline. It results in a blank screen for the normal duration of the routine.

continueRoutine code | try it

The expected behaviour is correct online. It also works offline if you set the version as 2022.1.4

This is to do with non-slip timing. Essentially, if you set continueRoutine = False during the frame loop, it takes note of the fact that the routine ended before the planned time so that the timer can be reset to 0 rather than having the expected duration subtracted (which we do for routines with a fixed duration as it prevents timing from slipping over several repeats). Because continueRoutine = False was set here before the routine, the frame loop never executes so it never learns that the routine was force ended.

I’ll put in a fix for the next version of PsychoPy so that what you did will work, in the meantime there’s two things you can do to avoid the problem:

  1. In your Begin Routine code, add routineForceEnded = True after continueRoutine = False - this means your experiment will know that the routine was skipped before its intended end time so won’t subtract the duration from the timer
  2. Move the code from Begin Routine to Each Frame, but put it inside of this if statement: if frameN == -1:. This means that continueRoutine will be set to False on the first frame, rather than before the first frame.

Do these two methods have any advantage in comparison to the one linked by @wakecarter?

Any should work :slight_smile: Yiannis’ solution works by skipping the loop altogether I believe