Visual Countdown timer for a loop

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

OS (e.g. Win10): MacOS Big Sur
PsychoPy version (e.g. 1.84.x): 2020.2.10
Standard Standalone? (y/n) If not then what?:
**What are you trying to achieve?: I have a loop that ends based on a certain amount of time passing, and would like a visual countdown timer that counts down based on the time I have set for the entire loop, not just the current routine.

**What did you try to make it work?: I have tried using a textbox stimulus that has $round(10.0 - $loop_timer, ndigits = 1) in the text area, but I got the following error:

Experiment/verbal shaping experiment copy", line 608, in
timer.setText(round(10.0 - loop_timer, ndigits = 1))
TypeError: unsupported operand type(s) for -: ‘float’ and ‘Clock’

Experiment ended.

If loop_timer is the name of your clock try loop_timer.getTime()

1 Like

Now I get this error:

Experiment/verbal shaping experiment copy", line 132, in
text=round(10.0 - loop_timer.getTime(), ndigits = 1),
NameError: name ‘loop_timer’ is not defined

Experiment ended.

Here is a picture of what I have included in my code component for the routine the loop acts upon.

I would define your loop timer in in EndRoutine of the last routine before the loop.

I think your first frame is running before the timer is created – hence the error.

Also, you should probable signal the end of the loop before you end the routine (since otherwise your end loop might not get executed).

Hi, I tried defining my loop timer in the EndRoutine of the routine right before my loop, but I still get the same error. What do you mean by signaling the end of the loop before I end the routine? The end loop is being executed because the loop and routine end at the time I have set, it’s just that the visual timer resets every time the loop resets.


I was able to get this working using the code included in Michael’s post found here:

However, when the timer runs out, the experiment simply ends, instead of continuing on to my remaining routines. Any suggestions?

nameOfYourLoop.finished ends the whole loop. Do you mean it’s missing other routines within the loop or after it?

It’s missing routines after the loop I am referring to.


you are asking the same question in different threads. You might want to focus your question in one thread and start a new thread if a new question comes up so that it can be found by others.

Best wishes Jens