Skipping a routine based on response and moving on to the next routine in que

PsychoPy version: v2024.2.4
What are you trying to achieve?:
The goal is to skip the upcoming routine in the task if there is a certain response given in the current routine. For eg. the question states that do you think the two games were same or different – if the participant answers “same” (by giving a touch response to an image displaying the word “same”), the task should skip the remaining routines and directly show the end routine. However, if the participant answers “different”, the task should move on to the next routine.

In the above picture, if the response in the routine “Task_Monitoring1” is “same” (which is a image response), the task should move on to the “end” routine. However, if the response is “different”, it should move on to TM2 routine.

What did you try to make it work?:
I tried to put the following code in Each Frame of Task_Monitoring1 routine

mouseloc = mouse.getPos()
if mouseloc[0] == mouserec[0] and mouseloc[1] == mouserec[1]:
    pass
elif same_image.contains(mouse):
    if t > minRT:
        mouserec = mouseloc
        mousetime= core.getTime()
        respMade = 1
        Task_Mon1_ans = True
        thisExp.addData('Task_Mon1_resp', same_image.name)
        continueRoutine = False
    else:
        mouserec = mouse.getPos()

elif diff_image.contains(mouse):
    if t > minRT:
        mouserec = mouseloc
        mousetime= core.getTime()
        respMade = 1
        Task_Mon1_ans = False
        thisExp.addData('Task_Mon1_resp', diff_image.name)
        continueRoutine = False
    else:
        mouserec = mouse.getPos()

and then the variable Task_Mon1_ans was put in the skipif of the TM2 routine

The code or the placement of the code doesnt seem to work here.
Please help me identify the issue here.

Thanks

I got the solution for the above issue after trying.

I added one variable in the Begin Routine of TaskMonitoring1 routine:

stimuli = [same_image, diff_image]
mouse = TM1_resp
mouserec = mouse.getPos()
respMade = 0
minRT = .3
Task_Mon1_ans = 0  ## this variable was added to check which image is selected in this rotuine##

In Each Frame:

mouseloc = mouse.getPos()
if mouseloc[0] == mouserec[0] and mouseloc[1] == mouserec[1]:
    pass
elif same_image.contains(mouse):
    if t > minRT:
        mouserec = mouseloc
        mousetime= core.getTime()
        respMade = 1
        Task_Mon1_ans = 1 ##valye of this variable changed for each image selection##
        thisExp.addData('Task_Mon1_resp', same_image.name)
        continueRoutine = False
    else:
        mouserec = mouse.getPos()

elif diff_image.contains(mouse):
    if t > minRT:
        mouserec = mouseloc
        mousetime= core.getTime()
        respMade = 1
        Task_Mon1_ans = 2
        thisExp.addData('Task_Mon1_resp', diff_image.name)
        continueRoutine = False
    else:
        mouserec = mouse.getPos()

In the Begin Routine tab of the next routine i.e. TM2, I just put one check:

if Task_Mon1_ans == 1:    ##this allowed me to skip the routine if the value of the variable is the response after which the current routine need to be skipped##
    continueRoutine = False

stimuli = [yes_image, no_image]
mouse = TM2_resp
mouserec = mouse.getPos()
respMade = 0
minRT = .3
Task_Mon2_ans = 0

I saw various similar queries in the forum, hope this helps someone who is still looking for solutions.

Thanks