Branching experiment code with mouse component

version: v2024.1.5

I’m trying to create an old-new recognition experiment, where when participants click the option ‘old’, it prompts them with a screen to probe their response further. If they hit ‘new’, they will simply be presented with the next trial.

What did you try to make it work?:
Using the keyboard component with a line of code works, where it redirects participants to a separate screen (written as doSM on the builder), I’ve included the code below:
if key_resp_5.keys == ‘z’:
doSM = 1
else:
doSM = 0

For the purposes of this study, using the mouse component would make things simpler. When using the mouse component to click ‘old’ and ‘new’, it goes through to the next trial. However, when trying to branch the experiment in the ‘old’ condition, the line of code does not work and instead, regardless of if ‘old’ or ‘new’ are selected, the participant sees the next trial. I have included the code for the mouse component below:

if (mouse.clicked_name == ‘OLD’):
doSM = 1
else:
doSM = 0

‘OLD’ is the name of the response as written on the psychopy text component title. mouse.clicked_name is the name of the column that generates the output for the response. There was also previously a syntax error message when I tried using the code for the mouse component, but I have not been able to reproduce that message.

I need support with creating code for when participants hit ‘OLD’, it redirects them to another screen. Any help would be appreciated!

Hello

You could print the value of mouse.clicked_name to the console to check whether you compare “OLD” with the proper value.

print(mouse.clicked_name)

Add this line of code just before your if-construction.

BTW, adding three ` formats the code properly.

Best wishes Jens

1 Like

I think OP is asking how to redirect people to another screen? The easiest way I’ve found within builder is to create a separate routines after that mouse-click response screen, and then add a code component to the routines to skip the routine if certain condition is met (such as if NEW response is collected).

if <new conditions>:
    continueRoutine = False

This effectively produces the desired experimental design of redirecting, while under the hood it’s just skipping a routine when not needed.