Creating a conditional routine within a loop

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

OS (e.g. Win10):
PsychoPy version (e.g. 1.84.x): Psychopy3 v2020.1.2
Standard Standalone? (y/n) If not then what?: y
What are you trying to achieve?:
I’ve seen several similar cases here, BUT, I’m not familiar with psychopy and its components (I opened it for the first time today), and I’m a beginner in coding python (who hasn’t coded anything for the past 2 years - life happened). That to say that I don’t understand the solutions to the similar cases and I need someone to walk me through (PLEASE). I am used to OpenSesame…but online running with pavlovia made me change to psychopy.

Well, I need a pause (with its proper screen and message) that happens regularly every 14 trials (I divided my list in 4 equal parts). The participant have to be able to press any key to continue the experiment. It must not have a timeout.

What did you try to make it work?:
I created a dedicated routine (PauseScreen) within the trial loop (Trial). In the Routine I put a text component with the message I want, no duration. And I also put a keyboard component, with no specified duration as well. In my conditions file, I have a column called “PAUSE” in which the value is “s” when the pause is to happen, and “n” when the trial should go normally. I just don’t know how to tell the builder to skip that routine in case $PAUSE == “s”
I also tried using the continueRoutine, but there is something wrong with my syntax.

I tried
If [PAUSE] == “n”
_continueRoutine = False

What specifically went wrong when you tried that?:
/* Syntax Error: Fix Python code */

Include pasted full error message if possible. “That didn’t work” is not enough information.

if PAUSE == "n":
     continueRoutine = False

That’s exactly what I did. I just wasn’t able to put the indentation here, so I used the underscore (here, in my description), instead.
Psychopy says it is syntax error as soon as I write continueRoutine.

Please could you show a screenshot of the code component?

Yes. Here it is:

uhh just notice the absence of the square brackets. I’m gonna try without it.

Same thing without the brackets…

I also tried this:

And got this:

Your if statement is missing its colon

I tried with colon as well. It doesn’t work. Apparently it is not recognizing the “continueRoutine” section. At least it doesn’t change color. Any ideas?

I was focusing on solving your syntax error. Are you running this online? If so, continueRoutine=False doesn’t work in Begin Routine, only in Each Frame.

I’m running it offline for now, but I do plan run it online. I figure out some other (ugly) solution;

I just divided my one trial loop into two with a pause routine in the middle. I’ll have extra work analyzing data, but that is what I was able to come up with…

The method I use for breaks is a loop around the break routine with nReps set to a variable which is 0 for most trials and 1 when I want the break to occur.

1 Like

That’s what I was trying to do. What do you write and where?

If you change your PAUSE column to 0 and 1 you could set nReps for the loop around your pause routine to PAUSE

How? What would I write at the nReps section?

Have you tried PAUSE (with PAUSE being 0 or 1 in your spread)?

This is based on you saying you have a column called pause. Personally, I now use the modulus of the loop number to make the decision. Have a look at my Prospective Memory LDT?

I tried… Don’t know what I’m doing wrong. I feel soooo dumb right now hahahaha
I set another column in my spreadsheet called STARTT for this coding with 0 and 1 as values. So I wrote on my nReps field for my loop STARTT (I also tried $STARTT). Now, when I run the experiment, It skips the loop and goes straight to the thanking screen, the routine after the loop, that closes the experiment.
Here is the code for the nReps set as STARTT (and $STARTT, as they generate the same code):

set up handler to look after randomisation of conditions etc

Block = data.TrialHandler(nReps=STARTL, method=‘sequential’,
extraInfo=expInfo, originPath=-1,
trialList=data.importConditions(‘Experiment2_AE_LIST4.xlsx’),
seed=None, name=‘Block’)

my experiment:

What is your Prospect Memory LDT? Where can I find it?

Thank you for showing your flow. The problem is that you have trials around your four trials routines and then an outer loop which also includes your pause screen. This is a different approach again. The one I’ve been suggesting here is to have your trials loop where your current Block loop is and then have a pause loop that only goes around PauseScreen_3 inside the trials loop. This is the one where you can set nReps to STARTT (not $STARTT if you want it to work online).

Here’s my Prospective Memory LDT experiment. Sign in · GitLab

1 Like

Thank you very much! That was the problem. I faced a little trouble still, bc I was calling my excel file inside the Pause Loop too. :woman_facepalming:t2: Once I left the field blank it worked!

And regarding your project… I’m not used to gitlab yet… Nor that kind of developer platform, so I can’t really understand much :sweat_smile: