Hi I am stuck in conditional branching and desperately asking for help
what I want to achieve is:
present two symbols on the screen (for example, a big star on the left and small star on the right)
let the subjects press keys to select (for example, press 'left" to choose left symbol)
highlight his selection (for example, a red border)
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:
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!
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ā¦
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.
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.
Thanks! it did solve the timing problem!
but the key press terminates the routine directly (I should not set continueRoutine = False ), 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!!!
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ā¦