How to end experiment with PsychoPy Coder if participant doesn't fit critera?

So I’m currently coding an experiment where participants have to have normal or corrected to normal vision and also normal colour vision. I want to terminate the experiment if participants do not fit that criteria. This is how my code looks so far:

info = {}
info[‘participant’] = ‘’
info[‘age’] = ‘’
info[‘sex’] = [‘Female’, ‘Male’, ‘Other’, ‘Prefer Not To Say’]
info[‘Do you have normal or corrected to normal vision?’] = [‘Yes’, ‘No’]
info[‘Do you have normal color vision?’] = [‘Yes’, ‘No’]

dlg = gui.DlgFromDict(info)
if not dlg.OK:

I don’t know how I would code to end if participants responded no to either (or both) of the vision related questions.

any advice?


do you finally want to run the experiment online? If this is the case, I would not end the experiment based on their response. A participant just might come back and answer your question not truthful. At least, that is what I have seen in my online experiments.

Anyway, this should do the trick

if expInfo['Do you have normal or corrected to nomal vision?'] == 'no' or expInfo['Do you have normal color vision?'] == 'no':

Best wishes Jens

Hi, I don’t actually plan on running the experiment with real participants. It’s just an assignment for the MRes I’m studying for. When I try to run this code it says “NameError: name ‘expInfo’ is not defined”. I don’t know a whole lot on PsychoPy at all, so I have no idea how to fix this. Any advice is really appreciated!


online participants are real participants :grin:

How do you program your experiment? Do you use the Builder or the Coder? expInfo is the default name created by the Builder via the settings menu (Experiment info). You access it via the gearwheel icon.

So probably, you have to change the expInfo to info. I suggest you program your experiment using the Builder.

Best wishes Jens

My grade is capped if I use Builder and they’d prefer us to use Coder, so I’m currently using coder. Makes everything so much harder :frowning:


how stupid IMHO. I am teaching myself. Anyway

expInfo = {
    'participant': f"{randint(0, 999999):06.0f}",
    'Do you have normal vision?': ['yes','no'],
    'Do you have normal color vision?': ['yes','no'],

should set up an Info-dialog. I copy&pasted it from the Python-script that the Builder wrote. Then at trial start, insert this

if expInfo['Do you have normal vision?'] == 'no' or expInfo['Do you have normal color vision?'] == 'no':

You see expInfo is just a dictionary, just with a different name than you used.

Best wishes Jens