OS (e.g. Win10): Windows10
PsychoPy version (e.g. 1.84.x): Standalone 2020.1.3
What are you trying to achieve?:
I’m new to Psychopy/Python and am primarily using Builder with added Code Components.
I am designing a task where 60 circles appear on the screen and on each trial, between 1 and 10 circles will turn black (one at a time), indicating that these are the target circles. After the last target circle is shown, participants will have a five second delay and will then be asked to click on the target circles. After they click on a circle, it will turn green if it was a target circle, and red it was not a target circle. Importantly, if there were 5 target circles, for example, they are only allowed 5 guesses/clicks when responding.
I’m having trouble ending the response routine after the allocated amount of clicks.
What did you try to make it work?:
I have tried the following code (sorry that it is so lengthy  I’m sure there’s an easier way to do this but it technically works!). My logic was to use a Click Count, and end the trial once a certain number of clicks were reached. ClickCount1 is set to 0 (in the begin experiment section).
Here, the target circles are circle7_3, circle16_3, circle29_3, circle35_3 and circle48_3. These will turn green if clicked, and the others will turn red if clicked.
if unaidedtrials.thisN == 0:
if unaidedresponses.isPressedIn(circle1_3):
circle1_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle2_3):
circle2_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle3_3):
circle3_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle4_3):
circle4_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle5_3):
circle5_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle6_3):
circle6_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle7_3):
circle7_3.fillColor = (0,128,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle8_3):
circle8_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle9_3):
circle9_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle10_3):
circle10_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle11_3):
circle11_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle12_3):
circle12_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle13_3):
circle13_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle14_3):
circle14_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle15_3):
circle15_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle16_3):
circle16_3.fillColor = (0,128,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle17_3):
circle17_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle18_3):
circle18_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle19_3):
circle19_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle20_3):
circle20_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle21_3):
circle21_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle22_3):
circle22_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle23_3):
circle23_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle24_3):
circle24_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle25_3):
circle25_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle26_3):
circle26_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle27_3):
circle27_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle28_3):
circle28_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle29_3):
circle29_3.fillColor = (0,128,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle30_3):
circle30_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle31_3):
circle31_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle32_3):
circle32_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle33_3):
circle33_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle34_3):
circle34_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle35_3):
circle35_3.fillColor = (0,128,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle36_3):
circle36_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle37_3):
circle37_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle38_3):
circle38_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle39_3):
circle39_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle40_3):
circle40_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle41_3):
circle41_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle42_3):
circle42_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle43_3):
circle43_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle44_3):
circle44_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle45_3):
circle45_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle46_3):
circle46_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle47_3):
circle47_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle48_3):
circle48_3.fillColor = (0,128,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle49_3):
circle49_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle50_3):
circle50_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle51_3):
circle51_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle52_3):
circle52_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle53_3):
circle53_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle54_3):
circle54_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle55_3):
circle55_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle56_3):
circle56_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle57_3):
circle57_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle58_3):
circle58_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle59_3):
circle59_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if unaidedresponses.isPressedIn(circle60_3):
circle60_3.fillColor = (255,0,0)
ClickCount1 = ClickCount1 + 1
if ClickCount1 >= 5:
continueRoutine = False
What specifically went wrong when you tried that?:
This trial that was meant to end after five clicks instead ended after one or sometimes two.
I read lots of other questions on this forum and realised that “mouse.isPressedIn” in the Every Frame section of the Code Component will keep reporting ‘True’ on every frame until the mouse is released. This means that my ClickCount1 variable obviously didn’t work as I intended it to.
Here are my questions:

Can someone please advise me on how I can end this routine after five clicks (and whether the same principle can be applied to subsequent trials that need to end after a different number of clicks)?

I assume that if I’m successful in ending this trial after five clicks, participants won’t actually be able to see their feedback for the fifth click (whether the circle that they clicked on was/was not a target). Is it possible to end the trial one second after the final click so they have time to see their feedback?
Thanks heaps!