# Ending routine after touchscreen

Dear,
I am trying an experiment in which the participant has to choose an answer touching the screen. After the touch, the selected polygon changes the contour color for 1 second and then the trial ends. Here is how I did the code:

• Each frame
mouseloc = mouse_1.getPos()
if mouseloc[0]==mouserec[0] and mouseloc[1]==mouserec[1]:
pass
elif polygon_1_2.contains(mouse_1):
if t>minRT:
polygon_1_2.lineColor = 'green'
trialEndTime1 = t + 1
trial_end1 = True
else:
mouserec = mouse_1.getPos()

elif polygon_1_3.contains(mouse_1):
if t>minRT:
polygon_1_3.lineColor = 'green'
trialEndTime1 = t + 1
trial_end1 = True
else:
mouserec = mouse_1.getPos()

if trial_end1 and t >= trialEndTime1:
continueRoutine = False

The problem is that after touching the polygon changes the colour but the trial does not end. Does someone knows how to fix it?
Best,

I can’t spot any issues with that.

Is this local or online?

I would investigate with some print statements. For example, print('trialEndTime1',trialEndTime1) when it is set and then print('t',t) next to continueRoutine = False

hi. thank you for the feedback. Its local experiment. What I noticed today is that if you touch the screen the polygon changes color, but it doesnt end the routine. In order to end the routine one have to drag the finger on the screen where a polygon is placed.

mouseloc = mouse_1.getPos()
if mouseloc[0]==mouserec[0] and mouseloc[1]==mouserec[1]:
pass
elif polygon_1_2.contains(mouse_1):
if t>minRT:
polygon_1_2.lineColor = 'green'
else:
mouserec = mouse_1.getPos()
elif polygon_1_3.contains(mouse_1):
if t>minRT:
polygon_1_3.lineColor = 'green'
else:
mouserec = mouse_1.getPos()
elif polygon_1_4.contains(mouse_1):
if t>minRT:
polygon_1_4.lineColor = 'green'
else:
mouserec = mouse_1.getPos()
elif polygon_1_5.contains(mouse_1):
if t>minRT:
polygon_1_5.lineColor = 'green'
else:
mouserec = mouse_1.getPos()

elif polygon_1_6.contains(mouse_1):
if t>minRT:
polygon_1_6.lineColor = 'green'
else:
mouserec = mouse_1.getPos()

if polygon_1_2.contains(mouse_1) or polygon_1_3.contains(mouse_1) or polygon_1_4.contains(mouse_1) or polygon_1_5.contains(mouse_1) or polygon_1_6.contains(mouse_1):
trialEndTime1 = t + 1.0
trial_end1 = True
if trial_end1 and t >= trialEndTime1:
continueRoutine = False

Your code is based on my code to get around the issue that local touchscreens have to be “stroked” to register a click response. That’s why it uses the contains method instead (a mouse hover response). The problem with this method is that when you aren’t touching the screen the last location continues to be returned as the mouse location, which is why there is code to pass if the coordinates haven’t changed. Your penultimate if statement in your new code ignores this so your trial will end after 1 seconds if the last touch in the previous routine is in one of the polygon locations.

To debug the code I would add a text component with a message (\$msg) set every frame and then you could set msg = whatever at different points in your code to see what is going on.

Hi, I dont think this is related to mouse position. I tried it a little more and even dragging the finger doesnt work always.

To debug, i did this:

trialEndTime1 = t + 1.0
trial_end1 = True
msg1 = t >= trialEndTime1
msg2 = trial_end1

msg1 is always returning False, while msg 2 returns True when i press a polygon. Looks like it is time-related.
Any idea?

Are you using t for anything?

Now you’ve narrowed it down to time, try putting the two halves of the time inequality in your messages

I think I found what is happening. I am using t to record the time when the screen is touched, and I am addnig 1s to t (variable trialEndTime1) to keep the new colored polygon on the screen for one more second. But since t is continuously updating, trialEndTime1 is also, and therefore it is never lower than t, and thats why the conditions to end the routine are never met.
Is it possible to save a “frozen” copy of the value of t for the moment when the screen is touched (polygon_1_2.contains(mouse_1))?

I usually include “and trialEndTime1 == 0” to the clause that sets a new value.

Sorry, but i didnt get it. tried a few things but nothing worked. Also, is t a reliable index for the reaction time in this case?
thank you for the help!