TypeError '>' not supported between instances of 'list' and 'float' (feedback only after 1.5s)

Hello! I’m trying to make a feedback loop saying “Too Slow!” only when they take longer than 1.5 seconds to respond, but it keeps crashing and I’m new to this so would appreciate some help :slight_smile:

This is the code I’ve put in the begin routine tab: (my text response component is called response1)
if response1.rt > 1.5:
continueRoutine = True
continueRoutine = False

When I run it it works fine skipping the routine but when it takes longer than 1.5s it crashes and says this instead of showing the message:

TypeError: ‘>’ not supported between instances of ‘list’ and ‘float’

Hello Hannah

the following code should work, at least it worked for me:

msg = " "
if (response.rt > 1.5):
    msg = "too slow"
    continueRoutine = True
    continueRoutine = False

put this in the Begin Routine tab. Place the code-element above your text-element, displaying the feedback message, set the text of your feedback text-element to $msg, and set the text to set every repeat.

Best Jens
P.S. I called the keyboard-element response and not response1.

I suspect that you are storing all responses in your keyboard component. That would make response1.rt a list. For the most recent rt you need response1[-1].rt

Alternatively, change the routine to only store one response.

However, you also don’t need continueRoutine=True, just have

if response1[-1].rt <= 1.5:


wakecarter’s solution is more elegant and parsimonious. And he found the error that I missed.

Best Jens

Hi I encountered the error of ‘TypeError: ‘Keyboard’ object does not support indexing’ when implementing similar codes
if respKey[-1].rt <= 1.5: msg="too slow"
in the Begin Routine. Any suggestion? Thanks!

Sorry – does respKey.rt[-1] work when storing all keyboard responses?

Also, I think you want >= 1.5 for slow RTs.

Using respKey.rt[-1] gave me another error message of “IndexError: list index out of range”, any idea? thanks
ps. thanks for noticing it, I used <=1.5 to debug to show the ‘too slow’ faster :slight_smile:

My attempts have been revised here (sorry not yet successful but found some consistent errors): I tried moving this section of code from Begin Routine to Each Frame, but I still get the error ‘TypeError: ‘Keyboard’ object does not support indexing’ when I use respKey[-1].rt (also try [0], same error output). Index rt using respKey.rt[-1] (also tried [0]) returned “IndexError: list index out of range.”

What is your keyboard component called?
It is in the previous routine, isn’t it?
Is it saving one key or all keys?
How does the previous routine end?

the keyboard component is ‘respKey’.
Perhaps the issue is that the code (tooSlow, see image below) is located in the current response (resp) routine? I store the last key in the respKey properties and allow three letters that correspond to the $correctAns. The text component used to display the ‘Response too slow’ message on each repeat. The preceding routine is displayed in the image below (showing on the screen 0.15s, no other components in this routine, as well as for fixation)


the feedback has to follow the response. Put your feedback in routine following your response routine.

Best wishes Jens

This post might help with getting RTs from keyboard lists.

Hi Jens thanks for your reply, feedback is indeed missed here. But I added in before ITI so that it won’t disturb the next fixation

@wakecarter thanks! it works now offline, but it is not working online. I will try to debug it. you are being very helpful, thanks!