Skipping routine if clicking on a particular object

Hi everybody,

I’m using the Builder 2022.2.4, I need your help because I’m not practical in writing codes.
I have 3 sequential routines (called: trial 1, trial 2, trial 3). In the “trial 2” there is an object called “polygon”.
My goal is this: if you click on this object, you skip the trial 3 and return directly to the trial 1.

How can I do it?
I know I have to add a code, but I don’t know how to do it.

Thanks
stefano

Hi Stefano,

you can add a code component to trial2 and use the following code

Begin routine

skip3 = False

Every frame

if mouse.isPressedIn(polygon):
    skip3 = True
  • “mouse” is the name of your mouse component.

Then, in trial3 add a code component with

Begin routine

if skip3:
    continueRoutine = False

Hope that does want you want to achieve!

1 Like

It works perfectly :grinning:
Thank you very much!

I have an additional question on the same topic.

Let’s suppose:

  • 6 sequential routines
  • 3 of them have a polygon white and a polygon black
  • 3 of them have a polygon red
    (see the flowchart below)

My goal is:

  • if I click on the polygon white → go to the beginning (a new trial starts)
  • if I click on the polygon black → go to the next routine
  • if I click on the polygon red → go to the next routine

In this case, you can extend the previous solution:

  • In the very first routine (Begin routine)
nextTrial = False
  • In every routine that has a white polygon (Each frame)
if mouse.isPressedIn(polygon_white): # will have to be adapted to each routine, because the polygons will have to have different names
    nextTrial = True
  • In routine 2 to 6 (Begin routine)
if nextTrial:
    continueRoutine = False

It worked in part, because (I think) the polygon white is clickable along with the polygon black.
So I added “if mouse.isPressedIn(polygon_black): nextTrial = False” and it worked.