I am looking to do two simple things, but their interaction is currently causing my experiment to crash.
The first thing: have a button change color when it is pressed and then end the routine .2 seconds after the color change. To do this, I made it so clicking the button does not end the routine, then added a mouse component, and then added code in the “Begin Routine” tab that says:
timer = core.Clock()
clicked = False
buttonPractice.color = 'white'
and code in the “Each Frame” tab that says:
if mouse.isPressedIn(buttonPractice):
buttonPractice.color = 'green'
clicked = True
endTime = timer.getTime()
currentT = timer.getTime()
if clicked and currentT > endTime + .2:
continueRoutine = False
This is working fine on its own.
At the same time, I have a video playing and when the video ends, the routine should end. This is also working fine on its own, as I have “End Routine” selected under the video component.
Generally, these two functions work fine. However, it is likely that a participant will click the button very close to the time the video is ending. When this happens, it crashes the program. My guess is that the program doesn’t know if it should end the routine with the video time or the code component time, so when they overlap, it goes haywire. However, I tried to fix that by de-selecting the “End Routine” choice in the video component and changing the last part of the “Every Frame” code to say:
if clicked and currentT > endTime + .2 or currentT >= VideoDur:
continueRoutine = False
but that didn’t fix the issue - it seemed like nothing changed. At this point, I assume the issue is the way that I’ve written the code, but I’m not sure how to tell PsychoPy to end the routine at the video duration (VideoDur) or the endTime + .2, whichever comes first. Any suggestions are appreciated - thanks!