psychopy.org | Reference | Downloads | Github

Using code to insert pauses within loops

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

OS (e.g. Win10): Win 7
PsychoPy version (e.g. 1.84.x): 1.81.02
Standard Standalone? (y/n) If not then what?: y

A while back I asked the following question and received a very helpful response which worked precisely as I wanted it to.

"I am new to PsychoPy (though for the most part I have found it very accessible and intuitive, so thank you!)

Welcome along…

I am not familiar with coding in Python either.

Well, below is a quick code snippet to show you how a tiny bit of Python can go a long way…

You don’t need to break your trials into blocks. The easiest arrangement to have here is a single loop surrounding your trial routine so that it will run all 96 trials in random order. What you can then have is a pause routine that interrupts that single loop, but only on trials 32 and 64.

i.e. insert a new routine. Just put a text stimulus on it saying something like “Take a break. Then press any key to continue.” Set it to last indefinitely (i.e. don’t give it a duration). Insert a keyboard component too, also set to last indefinitely and to force the end of the routine. The trick is to use a tiny bit of code that will only let this routine appear on the two specified trials. So insert a code component. In its Begin routine tab, put something like the code below. I’m assuming your loop is called trials. If it is called something else, use that name instead. Also, remember that Python is zero-based, so we will insert the pause after trials 31 and 63:

# Conditionally execute this pause routine:
if not trials.thisN in [31, 63]: # on most trials:
_ continueRoutine = False # don’t even start this routine"_

Only now I’ve changed universities, changed labs, and the same experiment doesn’t work any more. It seems like the conditional routine as above is just not doing anything. The code is still there but it is offering the pause after every trial. Is there a simple reason for this…such as me being an idiot?

David

It would seem most likely that this code isn’t actually executing. Alter the code to something like this for some temporary debugging:

if not trials.thisN in [31, 63]: # on most trials:
    continueRoutine = False # don’t even start this routine
else:
    print(trials.thisN)

I’ve had the exact same problem. Not sure why, but move the code from begin routine (where it was never executed) to each frame solves the problem.

I’m going to guess that this is because you are running a very old version of PsychoPy. A long time ago, continueRoutine was re-set to True after any “Begin routine” code was run, but that is no longer the case.

I think you are right, my version is 3.1.0 which is pretty old now… And I test with the latest version and then putting the code in ‘begin routine’ works.