Make a clock appear within a Routine also after its refresh

Hi everybody,

I need some help to reiterate two ‘if’ statements into a Routine.
My Routine has a movie in background lasting 10 minutes. Participants can check the clock while watching it. The clock is refreshed every 2 minutes. Within these 2 minutes the clock can be checked for a maximum of 3 times.
The code I wrote make me check the clock only for 3 times (for the whole duration of the movie). Thus, after the first refresh of the timer, if I used all the 3 available checks, the clock doesn’t appear again.
How can I solve it? Can I add some loop to let the code work also after the timer refresh?
Thanks for help :pray:

Here is my code component:

Begine Routine tab

Checktime = 0
keyCheckPressed = False
keyCheckPresses = 0
ClockDelay = 2
refresh = 120
k = 0
i = 0
m = 1
r  = 1

Each Frame tab

t = myClock.getTime()

if len(clock_resp.keys) > keyClockPresses and  len(clock_resp.keys) <= 3 :
      Checktime = t + CheckDelay
      keyCheckPressed = True
      keyCheckPresses += 1
      check_txt.setOpacity(1)
      check_box.setOpacity(1)
      thisExp.addData('RT_check_'+str(r)+'_'+str(m), check_resp.rt)
      m = m + 1
      r = r + 1
if t > Checktime and keyCheckPressed:
   check_txt.setOpacity(0)
   check_box.setOpacity(0)
   keyCheckPressed = False
#How can I create a loop of these if statements?     

check_resp_allKeys = []
check_resp.keys = []
check_resp.rt = []
    
if round(t) == k*refresh:
        i = 0
        k = k+1
        m=1

Change 3 maxPresses which starts at 3 and increases by 3 (+=3) after each period.

Thank you @wakecarter
If I change in len(clock_resp.keys) += 3 it gives me a syntax Error (invalid syntax)

Begin Experiment

maxPresses = 3

Each Frame

if len(clock_resp.keys) > keyClockPresses and  len(clock_resp.keys) <=  maxPresses:

and

if t > k*refresh:
        i = 0
        k += 1
        m=1
        maxPresses += 3

You don’t need to define t. It is automatically set to the time since the start of the routine.

It is not working. Again, after the refresh and after 3 presses, the clock does not appear anymore.

I don’t think you want these lines.

However, I note that you have both clock_resp and check_resp in your code. Should this be one or the other?

What code do you have now? Do you get an error message after 2 minutes or just no option to show the clock again?

Ok, I erased these lines and nothing changes.

I’m sorry, you’re right. Here I reported the wrong key in the first line. check_resp is the right one. In Psychopy it’s reported correctly. (I’m writing you from a different PC)

I don’t get any error. After 2 minutes (or after 3 presses), pressing check_resp key the clock doesn’t show up. It’s like the rule (to set opacity 1 to txt and box) is not updated when time refreshes. That is exactly what I’d need.
I also have another key component with no limit presses and I’m sure that the clock refreshes because I can check with it. Moreover, it appears on the screen anytime I press its related key overall the whole movie.

The actual code is:

Begine Routine tab

Checktime = 0
keyCheckPressed = False
keyCheckPresses = 0
maxPresses = 3
CheckDelay = 2
refresh = 120
k = 0
i = 0
m = 1
r  = 1

Each Frame tab

if len(check_resp.keys) > keyCheckPresses and  len(check_resp.keys) <= maxPresses :
      Checktime = t + CheckDelay
      keyCheckPressed = True
      keyCheckPresses += 1
      check_txt.setOpacity(1)
      check_box.setOpacity(1)
      thisExp.addData('RT_check_'+str(r)+'_'+str(m), check_resp.rt)
      m = m + 1
      r = r + 1
if t > Checktime and keyCheckPressed:
   check_txt.setOpacity(0)
   check_box.setOpacity(0)
   keyCheckPressed = False

if t > k*refresh:
    i = 0
    k += 1
    m = 1
    maxPresses += 3

maxPresses += 3

I corrected it here. In psychopy was ok and it still gives me the same problem.
[/quote]

Moreover, it is not refreshing after the forth minute, but after two minutes it refreshes again. Thus, time refreshes the first time when 2 minutes has passed and the second time when 6 minutes has passed.
It follows this scheme:
image