| Reference | Downloads | Github

Restarting a countdown timer

Dear all,

I am trying to insert a code snippet that allows users to call up a countdown timer via a keypress. The countdown should start at 15 and reset itself to 15 once it hit 0. However, currently it goes into the negative after 0.

So far I have inserted:
timer = core.CountdownTimer()
under the tab ‘before experiment’,

and then:
if timer == 0:
under the ‘begin experiment’ tab.

I don’t have any coding experience, so probably this is a really dumb approach. I appreciate your help! Thanks!

The code should more or less work, but you have to place it under different tabs:

Begin routine tab:

timer = core.CountdownTimer()

Each frame tab:

if timer.getTime() == 0:

Thank you so much for the suggestion! The issue with this is that the routines are very brief (there is a loop for the routine, so each routine lasts about 3sec). So if I insert the code into the ‘begin routine’ tab it means that the countdown returns to 15 at the start of each routine, rather than ever reaching 0. The countdown should run continuously, irrespective of the routine repetitions. Does that make sense at all?
Again, many thanks!

Ok, then you can just specify in the code to set the countdown timer only once (in the very first loop)

In the begin experiment tab

myCounter = 0

In the begin routine tab

if myCounter = 0:
    timer = core.CountdownTimer()

In the end routine tab

myCounter = myCounter + 1