Experiment stops when no key is pressed

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win10): Win10
PsychoPy version (e.g. 2024.2.4 Py 3.8): 2025.1.1

What are you trying to achieve?:

I am running a stop-signal reaction time experiment. Ppts will be shown different coloured circles and be asked to press either the left or the right arrow key (as a placeholder at the moment, in lieu of a button box) depending on the colour of the circle. There will be feedback for incorrect key presses and too slow responses (>1000ms, or no response).

At the moment, the feedback for incorrect responses and >1000ms responses works fine. But when no key is pressed, the ‘too slow!’ feedback is shown, but then the experiment completely stops - I need it to say ‘too slow!’, then move on to the next circle.

This is the code currently being used for feedback:

msg='wrong!'
if resp.rt > 1:
    msg='Too slow!'
if resp.corr: # stored on last run routine
    duration=0
else:
    duration=1

And the code used for recognising response time/if responses are too slow (this code prompts the inclusion of the ‘too slow!’ feedback - so it has the same job as some of the above code, but removing this code doesn’t solve the problem):

if resp.keys:
    if resp.rt > 1
       duration=1
    else: duration=0
else: duration=1

And this is what happens when no button is pressed - the experiment terminates:

      if resp.rt > 1:
TypeError: '>' not supported between instances of 'list' and 'int'
6.5782   WARNING   Stopping key buffers but this could be dangerous if other keyboards rely on the same
6.6669   WARNING   Stopping key buffers but this could be dangerous if other keyboards rely on the same
6.6671   WARNING   Stopping key buffers but this could be dangerous if other keyboards rely on the same

Any help would be much appreciated, I can’t figure out what is going wrong!

resp is saving all keys in a list. Try just saving the first key.

Hi,

Thank you for the advice! Do you know how I would code this? I don’t have a lot of experience with Python (I’ve made this with help from technicians and the ‘building experiments in psychopy’ book).

This hasn’t solved the issue unfortunately, but thank you for the tip!

Does it give exactly the same error? You need to have if resp.keys: to protect against checking the rt when there are no rts. You could also use if rest.rt[0] if the reaction time is being presented in a list.

Helloi @daisy.s

the code

can not work. It is missing a :

The following should work. Keep in mind that resp.rt is a list. So, you need to access the

if resp.keys:
    if resp.rt[0] > 1:
        duration = 1
    else:
        duration=0
else:
    duration = 1

Best wishes Jens

Hi Jens,

Thank you for your reply. It hasn’t solved the issue unfortunately, and now the experiment stops when I press a key and when I don’t… maybe it’s something to do with the loop?

It’s the same except for two extra warnings:

14.0733 WARNING t of last frame was 31.79ms (=1/31)
14.7797 WARNING No default speaker specified in Preferences / Hardware, using first speaker found: Speakers (Realtek High Definition Audio)

if resp.rt[0]

is placed below ‘if resp.keys:’ in my code, do you mean in place of this?

Hello @daisy.s

These are only warnings no errors. An error prevent an experiment from running. A warning just informs you that something might not be as expected.

Yes, you first check whether there is response if resp.keys:, and then check the rt.

The code you posted should not result in your experiment stopping.

What is the purpose of duration?

Do you have more than one keyboard-component?

Best wishes Jens

Hi Jens,

Sorry I was unclear, there is an error when it stops (if resp.rt > 1: TypeError: ‘>’ not supported between instances of ‘list’ and ‘int’), it’s just the same error as before so I didn’t include it.

‘Duration = 1’ is supposed to either prompt the routine to happen (if participants have been too slow); and ‘duration = 0’ is supposed to skip the routine (i.e. the ‘too slow!’ feedback) if participants responded in time. There’s only one keyboard component in this part of the experiment.

Hello @daisy.s

Does the following toy experiment work the way you want it to?

Feedback3.psyexp (16.2 KB)

If your routine continues despite the lack of a response, you might want to consider this in your if-construction.

Best wishes Jens

Hello Jens,

It does, thank you! The only difference is that the ‘too slow’ response should appear even when no button is pressed. I’ll have another look at my code compared to yours, and hopefully this can solve the problem.

Hello @daisy.s

change the if-construction to an ifelse-construction.

msg = " "

if resp.keys:
    if resp.rt >= 1:
        msg = "too slow"
else:
    msg = "too slow"

Best wishes Jens