How to skip routines?

How to skip routines using the mouse?

I apologize for the language.
I have a splash screen with 4 polygons (1,2,3,4)
I would like that when clicking on a polygon it jumps to a routine, without going through the others.

polygon 1 opens routine A
polygon 2 opens routine B
polygon 3 opens routine c…

you can check which polygon object was clicked with mouse.clicked_name and use that returned string to change a boolean statement (in a code object at the end of the routine) that corresponds with that object and the desired routine you want to jump to.

then start each routine with a code object which start with an if/else statement which if the corresponding boolean is the wrong value. if so, use ‘continueRoutine = False’, else the correct value enters the routine.

It doesn’t “jump” exactly but it will quickly skip over any routines you don’t want run.

let me know if this works. just tried it out for myself in a mini experiment and it seemed to work fine

can you tell me exactly how is this code? I tried in many ways :pensive:

let’s say polygon1 is a circle, polygon2 is a rectangle, and polygon3 is a triangle

mouse.clicked_name returns a list with two values [start_click, end_click]
ex. [‘polygon1’,‘polygon1’]
but you have to make sure you set up your mouse object properly:
‘end routine on press’ should be set to ‘valid click’
& the ‘clickable stimuli $’ should contain a list of the polygon object names
ex [polygon1,polygon2,polygon3]

in trial add a code object.
try something like this:

circ_bool = False # polygon1
tri_bool = False # polygon2
rect_bool = False # polygon3

if mouse.clicked_name[1] == ‘polygon1’:
circ_bool = True
elif mouse.clicked_name[1] == ‘polygon2’:
tri_bool = True

elif mouse.clicked_name[1] == ‘polygon3’:
rect_bool = True


let’s say routine ‘A’ is for circle, within that routine create a code object.
in the ‘begin routine’ window add an if statement like:

if circ_bool = False:
continueRoutine = False
# this should end the current routine

if you have code you need to run during that routine put it in an ifel statement checking that circ_bool == True so that it is not run unless circ_bool is True (ie. when you want to enter that routine)

^repeat that for the routines B&C, but using the correct booleans

hope this helps, lemme know if it works.

1 Like

I can’t see the error…
Thank you for your patience.



it is a line spacing issue. in python any code that you want to be contained within a loop or boolean statement must be spaced to the right. hit tab before starting a line after a loop or boolean statement and ends in a ‘:’. it is a syntax error. for example:


also, the clickable stimuli setting of the mouse object should be in a list format (ie. inside brackets)
see below.

this should clear it up. let me know if you need further help!

the syntax error appears only when I type “if” :man_facepalming:

just noticed something from your pictures earlier.

when you make a boolean statement you use ‘==’ to compare to variable values
‘=’ is used to assign a value

look at the difference between the if statements we posted pictures of.

when a statement is not complete or is not in the correct syntax the python → js translator will automatically say there is a syntax error

in the second code object photo you sent earlier it you put:
if bp_bool = False:

it should have been:
if bp_bool == False

ex. here I only use ‘=’ so it is like I am trying to assign a value to the variable reps. so I get a syntax error

ex. here I used the proper ‘==’ so it is evaluating the values on each side of the ‘==’

ex. here I have the correct evaluation statement, but improper spacing on the code I would like to run if the boolean condition is met. so I get a syntax error

Unfortunately it still didn’t work…now the message appears

AttributeError: ‘Mouse’ object has no


attribute ‘clicked_name’

ok well so now your syntax is correct, it’s just the mouse object which is not being called properly.

check what version of psychopy you have and look at the documentation of the mouse object for that corresponding version. I have v2021.2.3.

or you can go into the .csv data files and look at the saved data from the mouse object and call the variable which saves that value. I believe that’s what I did.

comment out the code in the end routine area. then print out that variable to see how it is stored so you can call it correctly. once you figure out the proper way to call it, substitute for mouse.clicked_name

Thanks! It worked. :rofl:

I created a list menu = [BP, BC, BS, BI…] (polygons) at the beginning of the routine.

At the end of the routine I used the command mouse.clicked_name[0] == ‘BP’: …