Error in refreshing of clock

Hi everybody!
I need some help :pray:
My Routine has a movie in background lasting 10 minutes. Participants can check the clock while watching it. The clock should refresh 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. I don’t get any error, but 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 – see the code) is not updated when time refreshes.
Moreover, time refreshes only after 2 min and 6 min have elapsed, following this path:
image

What’s wrong with code? How can I solve it, ensuring time refresh every 2 minutes and allowing 3 presses for the ‘check’ after every refhesh?

Thank you very much :sparkling_heart:

Here I report my code written in the Builder in a code component:

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

Hello

One way of checking that your if-construction does what you want it to do is to add a print command to the if-construction.

if t > Checktime and keyCheckPressed:
   print("t > Checktime and keyCheckPressed")
   check_txt.setOpacity(0)
   check_box.setOpacity(0)
   keyCheckPressed = False

aso.

In addition, you could also print out values of variabels.

print("keyCheckPresses: ", keyCheckPresses)

Could it be that that len(check_resp.keys) is not larger than keyCheckPresses after three key presses? I don’t see where you reset keyCheckPresses.

Best wishes Jens

Hi Jens,
First of all, thank you for your answer. keyCheckPresses is set = 0 in the Begin Routine tab.

Hello

I saw that you set keyCheckPressed at the Begin routine, but isn’t your routine 10 minutes aka one video long? Don’t you have to reset keyCheckPressed after 2 minutes?

Did you try to add print-statements to check when you enter an if-construction evaluates as true.

Best wishes Jens

I do want to reset keyCheckPresses after 2 minutes, so that every 2 minutes the participant can press check_resp (that is a key component in the Builder).

I can answer for it tomorrow. I tried only to use a print-statement in the first if-statement to verify keyCheckPresses and it actually printed only for 3 times.

Hi @JensBoelte ,
Your advice was very good! Using the print statements (in addition to some help from a colleague) I understood what was going in the wrong direction and we solved. Now the task works perfectly.
As soon as I can, I’ll share the code.
Thank you :slightly_smiling_face:

Best
Paola