| Reference | Downloads | Github

Problem with Conditional Branching in Builder

Hi I am stuck in conditional branching and desperately asking for help :cry:
what I want to achieve is:

  1. present two symbols on the screen (for example, a big star on the left and small star on the right)
  2. let the subjects press keys to select (for example, press 'left" to choose left symbol)
  3. highlight his selection (for example, a red border)
  4. pass to the next stimuli based on his choice (for example, a 7s-delay if choose left, and 4s-delay if choose right)

what I failed to achieve is step 4.
for the displaying the border and ending the current display, I put a code component before the keyboard and set ‘begin the routine’ like this below:

and for ‘each frame’ like this below:

my logic is: firstly display the border when a certain key was pressed, and let it display for 2s (using countdowntimer), and finish all, move to next display.
BUT it does not work: I pressed the key, the border shows up correspondingly, but will NOT disappear when the countdown ends, and the screen just stuck here, like forever…

Do I need to improve my code component in the builder or it can only be solved with coder?
It is my first time to post a topic, not sure whether I describe my problem clearly enough. Thanks sooo much for any possible solutions!

1 Like

Hi - the countdown timer will only go to 0 afik - so perhaps try


Best wishes,

1 Like

Hi, Oil
Thanks for replying!
Sadly I tried as you suggested, the problem remains…:cry:

Do you think you could upload your psyexp file? It would be easier to track the bug if I could see what else was going in the experiment.

Nope, time becomes negative.

In [8]: from psychopy.clock import CountdownTimer

In [9]: timer = CountdownTimer(0)

In [10]: timer.getTime()
Out[10]: -2.677877902984619

condition_delay_pilot.xlsx (8.1 KB)
delay pilot.psyexp (20.0 KB)
delay (15.8 KB)

Do I also need to upload the images?
Thanks a looooot!

Didn’t really dive into your program logic here, but I assume that you’re re-creating the timer object on “each frame”, hence the countdown never reaches zero…


Thanks, Richard!
I have the similar doubt… tried different ways to stop the displaying, but the problem remains.:cry:

I check the coder, seems time is only reset twice, one is at the beginning of trail,

and in the end of routine.

Sorry I am really a beginner with python and psychopy… :disappointed_relieved:

Richard is right - what is happening is that because the keyboard list always has ‘left’ or ‘right’ in it - your if statement always passes, meaning that the clock never reaches 0.

You can use a variable to indicate that the clock has started and should not be created again:

#in the begin routine tab
clockStart = 0

#every frame:
if choice.keys=='left' and clockStart == 0:
    clockStart = 1
if choice.keys=='right'and clockStart == 0:
    clockStart = 1

if border_right.autoDraw and timer.getTime()<0:
    continueRoutine = False
#    imageleft.finish == True
#    imageright.finish == True
#    textright.finish == True
#    textleft.finish == True
if border_left.autoDraw and timer.getTime()<0:
    continueRoutine = False
#    imageleft.finish == True
#    imageright.finish == True
#    textright.finish == True
#    textleft.finish == True

The imageleft.finish raises an exception, not quite sure what you are trying to achieve with that so I’ve commented them out.


1 Like

I would further suggest to only create the timers once (during Begin Experiment or so) and only reset them as the keyboard responses have been collected, i.e., instead of

timer = core.CountdownTimer(2)

you would simply do


if the timer was created previously. Should give higher temporal precision.


Thanks! it did solve the timing problem!
but the key press terminates the routine directly (I should not set continueRoutine = False :sweat:), that’s why I can trying to finish all the displaying images and text and move to next display…

I also try “imageleft.stop()” to stop the displaying and comes out an error "ImageStim object has no attribute stop“ …
how to solve that?.. Thanks!!!

Thanks! you guys are awesome! :tulip:

I try to set the opacity of image and text to 0 (imageleft.opacity == 0), it only worked with image :sweat_smile:



fail again, although it also works with image.:joy:

In manual 6.6 Defining the onset/duration of components, it said the condition can be used to make the component start or stop depending on the status of something else,
so I set the next display “blank” starts based on the status of the previous, but don’t know how to set the status of “something else” (like textleft here) to FINISHED after the key press.

I tried .stop() or .finish = True or .status = finished to terminate,won’t help…

Tried .setAutoDraw(False) and it worked!
and put the corresponding status to define the start of blan, but the following blank is missing…

Really confused…

You’ve got the start set to time rather than condition - is that the problem?

1 Like

YES!! i am stupid!! Thanks!!

Great! Good luck with your testing.

1 Like