Create a code that skip a routine after that it has been executed once

OS : Win10
PsychoPy version : v2022.2.2
What are you trying to achieve?: the “trials” loop is looping twice. In the second loop, I want it to skip “strategy_reminder” (without executing it) and continue to the routine “end_T2”.

This is the flow of the study:

What did you try to make it work?: I have tried to add this code to the routine in *Begin Routine
if trials.thisN == 2:
trials.finished = true

What specifically went wrong when you tried that?:
When the study arrives to “strategy_reminder” in the second time, it is indeed not showing it, however, the study freezes on a blank screen and does not continue to “end_T2”. Then I have to press escape and finish it.

if trials.thisN == 2 will end the loop on the third time, not the second. Do you also have code to end strategy_reminder on the second loop?

Hi @wakecarter , thank you for your answer!
I would love to get help to end strategy_reminder on the second loop (skip it, get out of trials loop and continue to end_T2 as seen in the flow).
Thanks!

In Begin Routine of strategy reminder

if trials.thisN == 1:
     trials.finished = True
     continueRoutine = False

Hey @wakecarter , are you sure?
I did this and it ran the “trials” loop just once, without executing strategy_reminder at all. In addition, the study froze on this point with a blank screen.
Your help is highly appreciated!
Lihi

Please could you upload your psyexp file.

Hi,

In the task_begin routine insert a code component and add the following in the begin routine tab:

myReps = 1 # initialise variable
if trials.thisN == 1: # second loop
    myReps = 0 # do not run

Surround your strategy_reminder routine only with a loop and add to the nReps field myReps.

If I am not mistaken this should do the job

BW
Yiannis

HI @Yiannis , now it working!!! Thanks a lot :slight_smile:
@wakecarter thank you too

1 Like