psychopy.org | Reference | Downloads | Github

Conditional Branching?

Hi, as you may guess I’m very new to psychopy! This is the first experiment I’m building!
OS : Win10
PsychoPy version: v.18.85.2

What are you trying to achieve?: At the very start of the experiment I ask the participant for consent. I want a ‘y’ keypress (yes I consent) to allow the participant to continue with the experiment. I want an ‘n’ keypress (no consent) to continue to a ‘thank you now go’ page.

What did you try to make it work?: I found a solution for a similar problem on the forum- the person had 2 images (I am presenting the consent page and thank you go information as jpegs) . The 2 images were shown simultaneously - but one of the images was set to 0 opacity. Then they used a code which said if x key is pressed then the opacity of the 2nd image is changed to 1. So it then becomes visible… I put it in the ‘each frame’ section.

if event.getKeys(‘n’): # if n key pushed,
noConsent.opacity = 1.0 # make noConsent appear

What specifically went wrong when you tried that?:
Both ‘y’ an ‘n’ keypresses continue to the experiment and the ‘thank you, next’ image is never shown.

Hi @Langers, you could add another routine after your consent page, that contains the exit message, and code for ending the experiment. You could make this routine display conditionally based on the response from the participant. If you add a keyboard component to the consent page, and a code component, then you could use the following code in the relevant tabs (see comments):

# Begin Experiment
exitExperiment = False

# End Routine
if resp.keys == 'n':
    exitExperiment = True

In the exit routine, add text component displaying your exit message with a duration of 5 seconds (suggested) and in the code component:

# Begin Routine
if not exitExperiment:  # Do not display routine if consent given
    continueRoutine = False

# End Routine
if exitExperiment:  # Quit experiment if consent not given
    core.quit()

That works, thank you! Sorry for the delay in replying.