Skipping routines in a single loop

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

OS (e.g. Win10):
PsychoPy version (2021.1.4):
**Standard Standalone? y
What are you trying to achieve?:
In a single loop, I have 5 routines (please see image). In the second routine (RespOptions), I am collecting participant responses (1, 2, and 3). If they respond with “3” I would like participants to see the rest of the routines in the loop. If they respond “1” and “2”, however, they should return back to the first routine in the loop and not do routines three, four, and five.

What did you try to make it work?:
I tried using a code component in routine 3 (verifySounds) where in the begin routine tab I wrote

if RespNOsKeys.keys= 1,2:
continueRoutine = false

I am not sure this code is correct, and I am not sure in which routine I should put the code.

What specifically went wrong when you tried that?:
Code does not work. Experiment proceeds no matter which response is input.Preformatted text

I should add that

RespNOsKeys.keys

Is the variable which captures participant responses in routine RespOptions.

Thank you for your help!!

Try printing RespNOsKeys.keys in “Begin routine” to confirm that it actually saves your keypresses.
Is RespNOsKeys a keyboard component?

if ‘1’ in RespNOsKeys.keys or ‘2’ in RespNOsKeys.keys:

Thank you for your reply. I tried the following:

if ‘1’ in RespNOsKeys.keys or ‘2’ in RespNOsKeys.keys:
    continueRoutine: False

But that didn’t work. It gave me the following error:

Alert 4205:Python Syntax Error in ‘End Routine’ tab. See 'if ‘1’ in RespNOsKeys.keys or ‘2’ in RespNOsKeys.keys:
’ on line number 1 of the ‘End Routine’ tab.

There are five routines in the loop (see image above). In the second routine (RespOptions) along, participants are asked a question and they respond with either 1, 2, or 3 via a keyboard response (RespNOsKeys.keys). If they respond with ‘3’, they should continue and do the remainder of the routines; but if they respond with ‘1’ or ‘2’ they should skip the remainder of the routines at start back at the beginning of the loop.

I am not sure what to enter into the code component. Further, I am not sure which tab to put the code in, and which routine the code component should be in (the error code above is from when I put the code in the second routine [where ppts respond with 1,2, or 3]).

Sorry for the many questions - still figuring out code components(!)

Any help would be massively appreciated.

Retype the quotes to make them dumb instead of ‘smart’.

Unfortunately, it is the same error message:

Alert 4205:Python Syntax Error in ‘End Routine’ tab. See 'if ‘1’ in RespNOsKeys.keys or ‘2’ in RespNOsKeys.keys:
’ on line number 1 of the ‘End Routine’ tab.

I think my issue is also where I am placing the code component? Should the code component be in the routine where the response is collected, or, in the next routine (which would be either skipped or run depending on the response from prev. routine)?

And, would it be begin or end routine tab for the code component?

Sorry for the masses of questions!

There’s no point issuing a continueRoutine = False command in End Routine when the routine is ending anyway.

Thank you for your reply. Yes, it is correctly saving the responses. And yes, it is a keyboard component. I can’t seem to figure out a way to discontinue with the rest of the routines based on a specified keyboard response. I am trying to program it so that if the participant presses ‘1’ or ‘2’, they return back to the beginning of the loop, but if they press ‘3’ they continue with the rest of the routines in the loop.

Thank you.

To skip a set of routines you either need continueRoutine = False code in Begin Routine of every routine you want to skip, or you put a loop around them with a variable nReps (set to 1 to play or 0 to skip).

I had the same issue. I had to enter code in the begin routine tab for each routine that I wanted to skip (routines 3, 4 & 5) for it to work correctly. I also used the same code in the end routine tab of the last routine that they will be presented with (routine 2) before it skips the rest of the routine. I hope that makes sense! I have included the code I used below (I have different key responses so you would need to edit it). My code is linked back to the response key for the last routine that they will be presented with before it either continues the routine or skips a bunch of subsequent routines:

if ThoughtPRAC.keys is not None:
if len(ThoughtPRAC.keys):
if ‘space’ not in ThoughtPRAC.keys:
continueRoutine = False
elif ThoughtPRAC.keys is None:
continueRoutine = False