# continueRoutine = False in Begin Routine tab has no effect

**URL:** <https://discourse.psychopy.org/t/continueroutine-false-in-begin-routine-tab-has-no-effect/9801>\
**Category:** Builder\
**Created:** [November 7, 2019, 9:57pm UTC](https://discourse.psychopy.org/t/continueroutine-false-in-begin-routine-tab-has-no-effect/9801 "2019-11-07T21:57:58Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![jderrfuss](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jderrfuss/32/5245_2.png) [@jderrfuss](https://discourse.psychopy.org/u/jderrfuss)\
**Post date:** [November 7, 2019, 9:57pm UTC](https://discourse.psychopy.org/t/continueroutine-false-in-begin-routine-tab-has-no-effect/9801/1 "2019-11-07T21:57:58Z")

</div>

**OS** : macOS  
**PsychoPy version** : 3.2.3  
**Standard Standalone?** : y  
**What are you trying to achieve?:** stop a routine from being run

I tried to stop a routine from being run by putting `continueRoutine = False` in the Begin Routine tab of a code component (and placing this component at the top of the routine). However, this setting is overwritten once the code is generated and thus has no effect:

```python
# ------Prepare to start Routine "trial"-------
# update component parameters for each repeat
continueRoutine = False
# (...)
continueRoutine = True

```

This seems similar to the issue described [here](https://discourse.psychopy.org/t/stop-a-routine-from-starting/1971).

Jan

---

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)\
**Post date:** [November 7, 2019, 10:13pm UTC](https://discourse.psychopy.org/t/continueroutine-false-in-begin-routine-tab-has-no-effect/9801/2 "2019-11-07T22:13:16Z")

</div>

That’s an ancient old issue: can’t understand how it has raised its head again if you are using version 3.2.3. Are you able to post your .psyexp file here?

---

<div class="post-metadata">

**Author:** ![jderrfuss](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jderrfuss/32/5245_2.png) [@jderrfuss](https://discourse.psychopy.org/u/jderrfuss)\
**Post date:** [November 7, 2019, 10:25pm UTC](https://discourse.psychopy.org/t/continueroutine-false-in-begin-routine-tab-has-no-effect/9801/3 "2019-11-07T22:25:38Z")

</div>

Thanks for your quick response, @Michael. Here you go.

[test.psyexp](https://discourse.psychopy.org/uploads/short-url/yp72WQgEZHsXkuMfQuXjbdRBy2f.psyexp) (7.1 KB)

---

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)\
**Post date:** [November 7, 2019, 11:01pm UTC](https://discourse.psychopy.org/t/continueroutine-false-in-begin-routine-tab-has-no-effect/9801/4 "2019-11-07T23:01:08Z")

</div>

Oh wow, this is bizarre. Can replicate that in 3.2.3 with other files too. Not sure how this hasn’t been causing problems for other people too.

Will need to call on @jon and @dvbridges for this one, as it is due to how Builder generates the .py file, which is not a part of the code base I am very comfortable with.

Jon: looks like there has been some sort of regression to this issue, which you addressed back in 2016:

> <https://github.com/psychopy/psychopy/issues/1143>
>
> To have conditional execution of a routine (e.g. a rest break every 10th trial), a code snippet like this is often...

As noted, not sure how this isn’t causing all sorts of grief to people, as setting `continueRoutine = False` is such a common technique. Have there been any recent changes that could have impacted this?

---

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)\
**Post date:** [November 8, 2019, 12:32am UTC](https://discourse.psychopy.org/t/continueroutine-false-in-begin-routine-tab-has-no-effect/9801/5 "2019-11-08T00:32:37Z")

</div>

Looking further into this, by setting “Use Psychopy version” in the experiment settings, the behaviour was correct up until version 3.1.5, and then from 3.2.0 onwards, the old behaviour re-emerged, of resetting `continueRoutine` to `True` immediately before the routine begins.

So Jan, as a short-term workaround you could tell Builder to use version 3.1.5 in the “Experiment settings” of your file (assuming that doesn’t cause issues with some other things that have changed recently, including the improved timing that came with version 3.2.0).

The first time you do this, there may be a slight delay, as PsychoPy will be downloading some of its 3.1.5 code in the background as required.

For us, the offending line in the repository is here:

> <https://github.com/psychopy/psychopy/blob/e937f5a84b8029c554bea383906427cc250af0ca/psychopy/experiment/routine.py#L150>

---

<div class="post-metadata">

**Author:** ![jderrfuss](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jderrfuss/32/5245_2.png) [@jderrfuss](https://discourse.psychopy.org/u/jderrfuss)\
**Post date:** [November 8, 2019, 8:12am UTC](https://discourse.psychopy.org/t/continueroutine-false-in-begin-routine-tab-has-no-effect/9801/6 "2019-11-08T08:12:27Z")

</div>

Thanks for looking into this further and the suggested workaround, Michael.

Jan

---

<div class="post-metadata">

**Author:** ![orig\_amir](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/orig_amir/32/4747_2.png) [@orig\_amir](https://discourse.psychopy.org/u/orig_amir)\
**Post date:** [November 12, 2019, 1:02pm UTC](https://discourse.psychopy.org/t/continueroutine-false-in-begin-routine-tab-has-no-effect/9801/7 "2019-11-12T13:02:45Z")

</div>

I had the same problem on a windows machine. Your workaround worked for me as well. Thanks!

---

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)\
**Post date:** [November 13, 2019, 3:16am UTC](https://discourse.psychopy.org/t/continueroutine-false-in-begin-routine-tab-has-no-effect/9801/8 "2019-11-13T03:16:10Z")

</div>

For future reference, there is a pull request that should address this issue here:

> <https://github.com/psychopy/psychopy/pull/2680>

so I am hoping this problem should be resolved in the next release (3.2.5), which should return to the expected behaviour.

---

<div class="post-metadata">

**Author:** ![frankbolton](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/frankbolton/32/6167_2.png) [@frankbolton](https://discourse.psychopy.org/u/frankbolton)\
**Post date:** [December 5, 2019, 10:35am UTC](https://discourse.psychopy.org/t/continueroutine-false-in-begin-routine-tab-has-no-effect/9801/9 "2019-12-05T10:35:34Z")

</div>

@Michael  
I’m trying to overcome the same bug (I got stuck on chapter 0.7 of Jon’s book)  
using your short-term workaround

Psychopy builder standalone v3.2.4  
Windows 10.

When I try to select builder version 3.1.5, the UI doesn’t give me that option or a place to enter code.  
 ![psychopy version select](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/2/b/2b96f7018b65d10d455d796a7dded99c37bf5aa4.png)  
Is it expected to update the XML of the .psyexp file?

```auto
<?xml version="1.0" ?>
<PsychoPy2experiment encoding="utf-8" version="3.2.4">

```

to

```auto
<?xml version="1.0" ?>
<PsychoPy2experiment encoding="utf-8" version="3.1.5">

```

I tried this and the experiment starts and appears to hang with an empty grey screen.

---

<div class="post-metadata">

**Author:** ![dvbridges](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/dvbridges/32/1918_2.png) [@dvbridges](https://discourse.psychopy.org/u/dvbridges)\
**Post date:** [December 5, 2019, 11:57am UTC](https://discourse.psychopy.org/t/continueroutine-false-in-begin-routine-tab-has-no-effect/9801/10 "2019-12-05T11:57:43Z")

</div>

Hi @frankbolton, if you are using a code component to end the routine on a particular condtion, then you need to move the `continueRoutine = False` command to the “Each Frame” tab.

---

<div class="post-metadata">

**Author:** ![frankbolton](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/frankbolton/32/6167_2.png) [@frankbolton](https://discourse.psychopy.org/u/frankbolton)\
**Post date:** [December 5, 2019, 2:01pm UTC](https://discourse.psychopy.org/t/continueroutine-false-in-begin-routine-tab-has-no-effect/9801/11 "2019-12-05T14:01:10Z")

</div>

@dvbridges thanks for the workaround! Sorted me out.

---

<div class="post-metadata">

**Author:** ![dvbridges](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/dvbridges/32/1918_2.png) [@dvbridges](https://discourse.psychopy.org/u/dvbridges)\
**Post date:** [December 5, 2019, 2:24pm UTC](https://discourse.psychopy.org/t/continueroutine-false-in-begin-routine-tab-has-no-effect/9801/12 "2019-12-05T14:24:43Z")

</div>

No problem, btw this will be fixed in the next release and you can revert back to the method recommended in the book.
