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

timer.getTime()<=0:

Best wishes,
Oli

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 pilot.py (15.8 KB)

sure!
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ā€¦

2 Likes

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
    border_left.autoDraw=True
    timer=core.CountdownTimer(2)
if choice.keys=='right'and clockStart == 0:
    clockStart = 1
    border_right.autoDraw=True
    timer=core.CountdownTimer(2)

if border_right.autoDraw and timer.getTime()<0:
    border_right.autoDraw=False
    continueRoutine = False
#    imageleft.finish == True
#    imageright.finish == True
#    textright.finish == True
#    textleft.finish == True
if border_left.autoDraw and timer.getTime()<0:
    border_left.autoDraw=False
    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.

Oli

2 Likes

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

timer.reset(2)

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

2 Likes

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:

Try

textleft.setOpacity(0)

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