Making a short screening task (conditonal coding)

OS
WIN10

PsychoPy version
2020.1.3.

Standard Standalone? (y/n) Y

What are you trying to achieve?:
I’m making a screening task to check whether participants can handle the mouse to choose and click on objects. We will collect data on time it takes to click on a simple square, and to move the cursor to a triangle and click on the triangle.
When completed in the correct order (clicked the square first, then the triangle), the participant will get a new screen with the square and the triangle, but on a different spot. This will be repeated in total 5 times.
If the participant clicks the triangle first, and then the square, a feedback should be shown that this was incorrect, and asking the participant to try again. After 3 wrong answers, the experiment is terminated, and the participant will be excluded from the experiment. Wrong answers should be recorded as well.

What did you try to make it work?:
I set up the squares and triangles, but I am completely new to conditional coding and I can’t figure it out.

I would be very grateful if anyone could help me with the appropriate code to make this task work-

The mouse component has a property called isPressedIn which stores the name of any components participants clicked on, so you can use the End Routine tab in a code component to check whether the clicks were in the desired position. For example, if your mouse component was called Mouse1, your square was Square1 and your triangle was Triangle1, you’d do:

if "Square1" in Mouse1.isPressedIn and "Triangle1" in Mouse1.isPressedIn:
# If participants clicked on both shapes...
        if Mouse1.isPressedIn.index("Square1") < Mouse1.isPressedIn.index("Triangle1"):
        # Did they click on the square before the triangle?
            wasCorrect = True

Then you’d add another routine after with the incorrect prompt in and put both routines within a loop (let’s call it Loop1) with a lot of repetitions. You can add something to the Start Routine tab in a code component in the prompt routine to say:

if wasCorrect:
    continueRoutine = False
    Loop1.nReps = 0

to skip this routine if they answered correctly, and to no longer repeat the loop.