# Block RT feedback for multiple responses

**URL:** <https://discourse.psychopy.org/t/block-rt-feedback-for-multiple-responses/32999>\
**Category:** Builder\
**Tags:** feedback\
**Created:** [January 29, 2023, 7:30pm UTC](https://discourse.psychopy.org/t/block-rt-feedback-for-multiple-responses/32999 "2023-01-29T19:30:13Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonathan\_silas](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jonathan_silas/32/36732_2.png) [@jonathan\_silas](https://discourse.psychopy.org/u/jonathan_silas)\
**Post date:** [January 29, 2023, 7:30pm UTC](https://discourse.psychopy.org/t/block-rt-feedback-for-multiple-responses/32999/1 "2023-01-29T19:30:13Z")

</div>

**OS** Win11  
**PsychoPy version** PsychoPy 2022.2.5

Hopefully, no stupid mistakes this time. I’m trying to give RT feedback at the end of a block. I have a detection task in different conditions so have more than one response component I want to average RTs and present to participants at the end of the block. But, so far I’m struggling to average RTs from one component and present that. I have tried to follow: [Builder - providing feedback — PsychoPy v2022.2.5](https://www.psychopy.org/recipes/builderFeedback.html)

meanRT = trials.data[‘respOne.rt’].mean  
fb\_text = “You got %.3f average reaction time” %(meanRT)

but I get  
meanRT = trials.data[‘long\_detect.rt’].mean  
KeyError: ‘respOne.rt’  
################ Experiment ended with exit code 1

Not sure why. Any ideas would be helpful. Once solved, I then need a mean of multiple responses to present back to participants, but one step at a time.

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![JensBoelte](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jensboelte/32/9060_2.png) [@JensBoelte](https://discourse.psychopy.org/u/JensBoelte)\
**Post date:** [January 30, 2023, 9:26am UTC](https://discourse.psychopy.org/t/block-rt-feedback-for-multiple-responses/32999/2 "2023-01-30T09:26:55Z")

</div>

Hello,

is your keyboard-component called respOne or long\_detect? Also, check the quotation marks. They should be '.

```auto
meanRT = trials.data['long_detect.rt'].mean
meanFB = 'You got %.3f average reaction time' %(meanRT)

```

not

```auto
meanRT = trials.data[‘long_detect.rt’].mean
fb_text = “You got %.3f average reaction time” %(meanRT)

```

when you surround code with triple ` your code gets formatted and it is easier to spot errors. When auto-translation (Auto → JS) is set in your code-component and the Python-code does not translate to JS, there is probably an error in your Python-code.

Best wishes Jens

---

<div class="post-metadata">

**Author:** ![jonathan\_silas](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jonathan_silas/32/36732_2.png) [@jonathan\_silas](https://discourse.psychopy.org/u/jonathan_silas)\
**Post date:** [January 30, 2023, 9:48am UTC](https://discourse.psychopy.org/t/block-rt-feedback-for-multiple-responses/32999/3 "2023-01-30T09:48:04Z")

</div>

thanks. Sorry for the confusion. actually code is:

trials.data[‘long\_detect.rt’].mean  
fb\_text = ‘You got %.3f average reaction time’ %(meanRT)

Double-checked the quotation marks, and I’m still getting the same error.

Any other things I should check?

Thanks!

---

<div class="post-metadata">

**Author:** ![JensBoelte](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jensboelte/32/9060_2.png) [@JensBoelte](https://discourse.psychopy.org/u/JensBoelte)\
**Post date:** [January 30, 2023, 10:03am UTC](https://discourse.psychopy.org/t/block-rt-feedback-for-multiple-responses/32999/4 "2023-01-30T10:03:39Z")

</div>

Hello Jonathan,

in the code you post you still have intelligent instead of dumb quotation marks. But it might be that the forum replaces dumb quotation marks with “intelligent” ones. Please surround your code with triple `.

Best wishes Jens

---

<div class="post-metadata">

**Author:** ![jonathan\_silas](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jonathan_silas/32/36732_2.png) [@jonathan\_silas](https://discourse.psychopy.org/u/jonathan_silas)\
**Post date:** [January 30, 2023, 10:34am UTC](https://discourse.psychopy.org/t/block-rt-feedback-for-multiple-responses/32999/5 "2023-01-30T10:34:56Z")

</div>

Hi Jens,

Thanks. My code copy & pasted this time around triple ` . I think these are the right quotes:

```auto
meanRT = trials.data['long_detect.rt'].mean
fb_text = 'You got %.3f average reaction time' %(meanRT) 

```

I think that’s right?

Many thanks.  
Jon

---

<div class="post-metadata">

**Author:** ![jonathan\_silas](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jonathan_silas/32/36732_2.png) [@jonathan\_silas](https://discourse.psychopy.org/u/jonathan_silas)\
**Post date:** [January 30, 2023, 10:37am UTC](https://discourse.psychopy.org/t/block-rt-feedback-for-multiple-responses/32999/6 "2023-01-30T10:37:41Z")

</div>

Apologies - had to edit a few times getting used to using the tripple `.

---

<div class="post-metadata">

**Author:** ![JensBoelte](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jensboelte/32/9060_2.png) [@JensBoelte](https://discourse.psychopy.org/u/JensBoelte)\
**Post date:** [January 30, 2023, 10:54am UTC](https://discourse.psychopy.org/t/block-rt-feedback-for-multiple-responses/32999/7 "2023-01-30T10:54:05Z")

</div>

That looks good.

Does this work for you? Just press y, when “press” is displayed (five trials).

[blockFeedback.psyexp](https://discourse.psychopy.org/uploads/short-url/5DOrI6pO2OkQ82kTA3VykhJGl8P.psyexp) (12.2 KB)

You did not answer one question.

> [@jonathan\_silas](#):
>
> KeyError: ‘respOne.rt’

So, does the code you wrote and the components match in names and spelling?

Do you have anything named respOne.rt?

Best wishes Jens

---

<div class="post-metadata">

**Author:** ![jonathan\_silas](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jonathan_silas/32/36732_2.png) [@jonathan\_silas](https://discourse.psychopy.org/u/jonathan_silas)\
**Post date:** [January 30, 2023, 11:18am UTC](https://discourse.psychopy.org/t/block-rt-feedback-for-multiple-responses/32999/8 "2023-01-30T11:18:47Z")

</div>

Thanks Jens - really helpful.

Yes - that file works fine. I changed my code to make it closer to what you have in the file by adding in the begin experiment tab:

```auto
fb_text=""
meanRT=""

```

and the code in the begin routine reads:

```auto
meanRT = trials.data['long_detect.rt'].mean()
fb_text = 'You got %.3f average reaction time' %(meanRT)

```

> [@JensBoelte](#):
>
> So, does the code you wrote and the components match in names and spelling?
> 
> Do you have anything named respOne.rt?

- no sorry, that was me poorly editing the error output trying to make it more understandable. error code reads as such:

```auto
meanRT = trials.data['long_detect.rt'].mean()
KeyError: 'long_detect.rt'

```

Thanks again for your time and support!  
Jon

---

<div class="post-metadata">

**Author:** ![jonathan\_silas](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jonathan_silas/32/36732_2.png) [@jonathan\_silas](https://discourse.psychopy.org/u/jonathan_silas)\
**Post date:** [January 30, 2023, 11:25am UTC](https://discourse.psychopy.org/t/block-rt-feedback-for-multiple-responses/32999/9 "2023-01-30T11:25:27Z")

</div>

not sure if it helps but this is the routine in the trials loop it’s aimed at:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/5/3/53b1c600a6180731dce0df9133feaeb2d0ae89f3.png)

And this is the loop:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/b/5/b54365c785fbdaf8433857f4e2717258650f1c55.png)

Thanks!  
Jon

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [January 30, 2023, 12:45pm UTC](https://discourse.psychopy.org/t/block-rt-feedback-for-multiple-responses/32999/10 "2023-01-30T12:45:17Z")

</div>

Is this issue happening because the participant always responds during short\_detect? Why do you have separate keyboard components? Won’t that mess up your mean RT anyway?

---

<div class="post-metadata">

**Author:** ![jonathan\_silas](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jonathan_silas/32/36732_2.png) [@jonathan\_silas](https://discourse.psychopy.org/u/jonathan_silas)\
**Post date:** [January 30, 2023, 1:03pm UTC](https://discourse.psychopy.org/t/block-rt-feedback-for-multiple-responses/32999/11 "2023-01-30T13:03:48Z")

</div>

Thanks.

No - the participant will respond, depending on the condition at either short\_detect or long\_detect. I’ve used separate keyboard responses for two reasons - 1. So I can easily calculate response time to either short\_target or long\_target depending on the trial 2. So I can view data easily by correct response - if a response is recorded in short\_detect on a long\_target trial this would be incorrect… or maybe this is a hangover from moving recently from e-prime(?)  
Thanks!

---

<div class="post-metadata">

**Author:** ![JensBoelte](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jensboelte/32/9060_2.png) [@JensBoelte](https://discourse.psychopy.org/u/JensBoelte)\
**Post date:** [January 30, 2023, 3:13pm UTC](https://discourse.psychopy.org/t/block-rt-feedback-for-multiple-responses/32999/12 "2023-01-30T15:13:38Z")

</div>

Hello Jonathan

AFAIK you need two physical keyboards to use two keyboard-components. Now two keyboard-components “fight” for one response.

Best wishes Jens

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [January 30, 2023, 4:09pm UTC](https://discourse.psychopy.org/t/block-rt-feedback-for-multiple-responses/32999/13 "2023-01-30T16:09:57Z")

</div>

The two components are active at different times so that should be fine. Personally I’m more familiar with appending RTs to lists and calculating means from that than interrogating the trials.data.

---

<div class="post-metadata">

**Author:** ![JensBoelte](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jensboelte/32/9060_2.png) [@JensBoelte](https://discourse.psychopy.org/u/JensBoelte)\
**Post date:** [January 30, 2023, 4:26pm UTC](https://discourse.psychopy.org/t/block-rt-feedback-for-multiple-responses/32999/14 "2023-01-30T16:26:23Z")

</div>

Hello,

well, if two keyboards-components when when they don’t overlap in time, then the code posted above should work.

Best wishes Jens

---

<div class="post-metadata">

**Author:** ![jonathan\_silas](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jonathan_silas/32/36732_2.png) [@jonathan\_silas](https://discourse.psychopy.org/u/jonathan_silas)\
**Post date:** [January 30, 2023, 4:37pm UTC](https://discourse.psychopy.org/t/block-rt-feedback-for-multiple-responses/32999/15 "2023-01-30T16:37:23Z")

</div>

Thanks both.

I’ll muck about - if one keyboard response fixes the problem, I’ll do as Wakefield suggests and deal with the data as it comes.

Odd that the file code doesn’t work as it is though.

I’ll let you know how it goes.  
Thanks

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [January 30, 2023, 4:42pm UTC](https://discourse.psychopy.org/t/block-rt-feedback-for-multiple-responses/32999/16 "2023-01-30T16:42:50Z")

</div>

What error are you getting now? Presumably it can’t still be KeyError: ‘respOne.rt’.

---

<div class="post-metadata">

**Author:** ![jonathan\_silas](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jonathan_silas/32/36732_2.png) [@jonathan\_silas](https://discourse.psychopy.org/u/jonathan_silas)\
**Post date:** [January 30, 2023, 4:50pm UTC](https://discourse.psychopy.org/t/block-rt-feedback-for-multiple-responses/32999/17 "2023-01-30T16:50:48Z")

</div>

Hi,

tried modifying the routine with one response like so:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/5/9/593e3dc3f8f0511b623aefa3f2bb76b9034b3db7.png)

new code in BlockFeedback routine:

```auto
meanRT = trials.data['detect.rt'].mean()
fb_text = 'You got %.3f average reaction time' %(meanRT)

```

And i get the same error:

```auto
meanRT = trials.data['detect.rt'].mean()
KeyError: 'detect.rt'

```

Any more ideas?  
Thanks

---

<div class="post-metadata">

**Author:** ![JensBoelte](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jensboelte/32/9060_2.png) [@JensBoelte](https://discourse.psychopy.org/u/JensBoelte)\
**Post date:** [January 30, 2023, 6:19pm UTC](https://discourse.psychopy.org/t/block-rt-feedback-for-multiple-responses/32999/18 "2023-01-30T18:19:58Z")

</div>

Hello

can you print detect.rt to the console?

```auto
print(detect.rt)

```

or

```auto
print(trials.data['detect.rt'])

```

Insert a code-component following the keyboard-component in the end-routine tab. The first print-command will print the current RT, the second the RT-list.

Best wishes Jens

---

<div class="post-metadata">

**Author:** ![jonathan\_silas](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jonathan_silas/32/36732_2.png) [@jonathan\_silas](https://discourse.psychopy.org/u/jonathan_silas)\
**Post date:** [January 31, 2023, 12:33pm UTC](https://discourse.psychopy.org/t/block-rt-feedback-for-multiple-responses/32999/19 "2023-01-31T12:33:12Z")

</div>

Hey, thanks again.

I now get these errors before the BlockFeedback routine:

```auto
meanRT = trials.data['detect.rt'].mean()
KeyError: 'detect.rt'

```

or

```auto
    print(trials.data['detect.rt'])
KeyError: 'detect.rt'

```

depending on whether I enter

```auto
print(detect.rt)

```

or

```auto
print(trials.data['detect.rt'])

```

Respectively.

Bit stuck.

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [January 31, 2023, 12:49pm UTC](https://discourse.psychopy.org/t/block-rt-feedback-for-multiple-responses/32999/20 "2023-01-31T12:49:05Z")

</div>

That error means that trials.data doesn’t contain a field called detect.rt.

As I said before, I am unfamiliar with whether you can use trials.data (or indeed whether that is how you are supposed to use it). I would instead have something like rtList = in Begin Experiment and rtList.append(detect.rt) in End Routine. Then meanRT = rtList.mean() should work.

[Next page](https://discourse.psychopy.org/t/block-rt-feedback-for-multiple-responses/32999.md?page=2)
