| Reference | Downloads | Github

Conditions for advancing to the next screen

I would like to have the experiment advance to the next screen (force end of routine) after a rating is selected on the slider AND a keyboard is pressed. I was wondering if there might be a way to implement those two conditions.

What did you try to make it work?:

I tried adding the keyboard component with a “force end of routine” and checking the “force end of routine” button for the sliders.

What specifically went wrong when you tried that?:
The experiment advances to the next screen after a slider is marker is selected.

You could try this, checking for valid keypresses only when a rating has been made


if resp.keys and not slider.getRating():
    # reset keys
    resp.keys = []
    resp.rt = []
elif resp.keys and slider.getRating():
    continueRoutine = False


if (resp.keys !== undefined && (slider.getRating() === undefined || slider.getRating === 'undefined')) 
    // reset keys
    resp.keys = undefined
    resp.rt = undefined
else if (resp.keys !== undefined && slider.getRating()) 
    continueRoutine = false;
1 Like

Hi @dvbridges - thank you for the suggestion.
It does not work so far.

I tried the following: placing the code into “begin routine” and into “end routine”- no luck with either. I also changed the “resp” to match the name of my keyboard input. The Python code looks as follows:

if key_resp_4.keys and not valence11.getRating():
    # reset keys
    key_resp_4.keys = []
    key_resp_4.rt = []
elif key_resp_4.keys and valence11.getRating():
    continueRoutine = False`

Should I place this elsewhere?

thank you for all your help,

No problem. This should go in the “Each Frame” tab of the code component in the relevant routine.

1 Like