| Reference | Downloads | Github

TypeError: 'float' object is not subscriptable for trial-by-trial response (time) dependent feedback


I am trying to set the code within a feedback routine (on the builder). The routine consists of the feedback code, followed by the feedback text (which I have set to $msg). In the feedback code, I am trying to have trial-by-trial response dependent feedback, where if the response is correct (go_resp.corr == 1, the automatic correct answer variable Psychopy made from my previous routine, as seen in the output file), and under a certain reaction time (using go_resp.rt - the automatic response time variable for the keyboard component of my previous routine). Psychopy is able to extract whether or not it is a correct response from the go_resp.corr variable, but when I add the go_resp.rt code it brings up the error (referring to that specific line) saying: TypeError: ‘float’ object is not subscriptable. The same reaction-time dependent feedback code has worked for someone else in a previous version of Psychopy, so it might be a case of updates to how resp.rt is extracted? Any help with this would be greatly appreciated. Here is my code:

if go_resp.corr and go_resp.rt[0] <= 0.75:
msg = “+20 points!”

elif go_resp.corr and go_resp.rt[0] > 0.75:
msg = “+10 points!”

msg = “-10 points!”

I’m guessing in the older version of PsychoPy, .rt was a list or tuple, but now it’s a float. If you remove those references to [0] it should work - the error is telling you that you’re trying to access the 0th element of rt, but rt isn’t an array of elements, it’s just a single number.

I’d expect it to be a list if your keyboard component saves all responses and a float if it only saves the first or last.


Thanks for your reply! When I try it without the zero I get a different error: TypeError: ‘<=’ not supported between instances of list and float. Do you know what this could mean?


Thank you that makes sense. However I only want to save one response (and time) but also want to set the if statement based on the resp.rt as stated, for which it needs to be a list (?). Is there any way to do this?

Have you tried setting the keyboard to save one response and then using the following?

if go_resp.corr and go_resp.rt <= 0.75:
     msg = "+20 points!"
elif go_resp.corr and go_resp.rt > 0.75:
     msg = "+10 points!"
     msg = "-10 points!"


I fixed this my rounding off the 0.75 (*1000) before setting the conditions. Psychopy wasn’t recognising a decimal number as an integer!

Thanks all,