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
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
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
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: