# Commands are called twice after time condition met

**URL:** https://discourse.psychopy.org/t/commands-are-called-twice-after-time-condition-met/43901
**Category:** Coding
**Tags:** timing
**Created:** [February 14, 2025, 2:41pm UTC](https://discourse.psychopy.org/t/commands-are-called-twice-after-time-condition-met/43901 "2025-02-14T14:41:37Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Gabriel\_Terhoch](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/gabriel_terhoch/32/34275_2.png) [@Gabriel\_Terhoch](https://discourse.psychopy.org/u/Gabriel_Terhoch)
#### Post date: [February 14, 2025, 2:41pm UTC](https://discourse.psychopy.org/t/commands-are-called-twice-after-time-condition-met/43901/1 "2025-02-14T14:41:37Z")

</div>

In 2024.2.4 version,

Commands are called twice after time condition met:

```auto
if segundos == 5 and not segundos_5_executado: # second condition was my unsuccefull attepmt to solve the problem.
    
    segundos_5_executado = True # same. In the beggining of Routine, I set the state of this variable to False.
    segundos = 0
    contador -= 5 #This is running twice.
    reforcar = 0 
    tentativasLag += 1 #So as this.
    Inicio = relogio.getTime()
    continueRoutine = False

```

I tried moving both “contador -= 5” and “tentativasLag += 1” to End Routine, calling it with segundos\_5\_executado == True. Still unsuccefull. I have no ideia why it is running twice.

---

<div class="post-metadata">

### Author: ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)
#### Post date: [February 14, 2025, 10:19pm UTC](https://discourse.psychopy.org/t/commands-are-called-twice-after-time-condition-met/43901/2 "2025-02-14T22:19:47Z")

</div>

Do you have an ITI? If not, then maybe the whole routine is running twice without you noticing.

Add print commands

> [@Wakefield's Daily Tips](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/4):
>
> Use Print statements When debugging, print statements can be very helpful to track down errors or unexpected behaviour. I tend to use them in one of two ways: print('trial setup started') Sometimes I won’t know where the error is, especially if there is a problem during the initial setup of the components or Begin experiment code. The components of each routine are set up in turn from top to bottom. Therefore, if you have a flow with routines called start, trial and finish and put print('tri…

Check you are using the latest code

> [@Wakefield's Daily Tips](https://discourse.psychopy.org/t/wakefields-daily-tips/43371):
>
> Run the latest version of your experiment When you synchronise changes to your experiment, you may need to clear your browser cache to see those changes online (using Ctrl-Shift-R, Ctrl-F5, or equivalent). If this does not work (for example because a spreadsheet has changed rather than the JavaScript files or you are using a mobile device) use an incognito (private) browser tab. A participant will not need to do this, so long as they have not already tried a previous version of your experiment. …

---

<div class="post-metadata">

### Author: ![Gabriel\_Terhoch](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/gabriel_terhoch/32/34275_2.png) [@Gabriel\_Terhoch](https://discourse.psychopy.org/u/Gabriel_Terhoch)
#### Post date: [February 15, 2025, 12:03am UTC](https://discourse.psychopy.org/t/commands-are-called-twice-after-time-condition-met/43901/3 "2025-02-15T00:03:03Z")

</div>

Thank you @wakecarter. The routine is indeed running twice, with the aggravating that for some reason calling

> segundos\_5\_executado = False

at the beggining of the new routine is useless, as it seems that is quickly turned True and the routine ends. After this extra ending, everything works fine.

For context, I have a Loop of Trial Routine + Reward Routine. Trial routine keeps repeating until criteria is achieved for Reward Routine to be presented.

If criteria is not met in 5 s, then the person lose some points:

> contador -= 5

, one trial is added to total number of trials:

> tentativasLag += 1 # unfortunately, since one of the three possible ends of routine should not increase the number of trials, I can’t just work with the builder counter to end my loop, but I guess this should work.

and the trial routine start again.

I have to have a timer that starts on the beggining of the first Trial and restarts either at 5 s or just after Reward Routine. For some reason, it seems like this timer is not reseting after the first routine ending after 5 s elapsed without reward, only after the extra, unplanned, routine.

Also, I’m runnning this offline.

---

<div class="post-metadata">

### Author: ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)
#### Post date: [February 15, 2025, 7:31am UTC](https://discourse.psychopy.org/t/commands-are-called-twice-after-time-condition-met/43901/4 "2025-02-15T07:31:45Z")

</div>

> [@Gabriel\_Terhoch](#):
>
> `segundos == 5`

How does this happen? There must be more code?

---

<div class="post-metadata">

### Author: ![Gabriel\_Terhoch](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/gabriel_terhoch/32/34275_2.png) [@Gabriel\_Terhoch](https://discourse.psychopy.org/u/Gabriel_Terhoch)
#### Post date: [February 15, 2025, 4:16pm UTC](https://discourse.psychopy.org/t/commands-are-called-twice-after-time-condition-met/43901/5 "2025-02-15T16:16:02Z")

</div>

That was it @wakecarter. There was an “extra” setting of segundos = another variable at the beggining of routine. That is probably something that came in an anternative version of the program that I carelessly didn’t pay enough attention when rebuilding the experiment.  
Thank you very much for your help.
