I’m trying to get a code component to work that will mean if participants either select an incorrect answer or timeout of the trial, the Experiment quits and a dialog box pops up with a message. The former works (incorrect response >>> quit + dialog box), but not the latter (timing out).
OS: MacOS Catalina 10.15.6
PsychoPy version: v2020 (2.5)
**Standard Standalone? ** Y
What are you trying to achieve?: I want to include a very simple attention check in my experiment (this will eventually be online via Pavlovia, but I’d like to get it working in Builder first before converting to JSPsych). So far, if the participant answers incorrectly, I can get the Experiment to terminate with a dialog box that explains what happened and why, but I also wanted to add in a time limit - e.g. if they take over 10 seconds to make a response, then the Experiment also terminates. There is only one trial.
What did you try to make it work?: Apologies, because I’m a beginner to this all. I’m using a mouse as a response (currently set to ‘valid click’ - see screenshot) and I’ve added a code component:
# Begin routine
startTime = globalClock.getTime()
# End routine
if mouse_6.clicked_name [0] != corrAns or startTime >10:
thiswin=visual.Window(fullscr=False, allowGUI=True)
win.close()
thisdlg = gui.Dlg()
thisdlg.addText("msg")
ok_data=thisdlg.show()
if thisdlg.OK == True:
core.quit()
The Experiment runs, and the code to close and display the dialog box works, but the trial does not time out. I don’t know if it’s something to do with using the global clock, or if it’s something to do with using ‘or’; if I try to use ‘if’ and then ‘elif’, the Experiment just quits no matter what you do once you make a response (but still doesn’t time out). I can of course set the images/mouse on Builder to end after 10 second so the Experiment just ‘fails’, but I think it’s good to let participants know why - hence the dialog box. I’ve tried to read the documentation for psychopy.core clock and a couple of other posts but still don’t understand how to formulate this correctly so it works. Any help greatly appreciated!!
Screenshots: