# Sum trial feedback for block not working online

**URL:** <https://discourse.psychopy.org/t/sum-trial-feedback-for-block-not-working-online/27451>\
**Category:** Online experiments\
**Created:** [February 16, 2022, 4:50pm UTC](https://discourse.psychopy.org/t/sum-trial-feedback-for-block-not-working-online/27451 "2022-02-16T16:50:23Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tin\_Tin](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/tin_tin/32/14611_2.png) [@Tin\_Tin](https://discourse.psychopy.org/u/Tin_Tin)\
**Post date:** [February 16, 2022, 4:50pm UTC](https://discourse.psychopy.org/t/sum-trial-feedback-for-block-not-working-online/27451/1 "2022-02-16T16:50:23Z")

</div>

URL of experiment: [NegativeSelfAssociation [PsychoPy]](https://pavlovia.org/run/jantolin/negativeselfassociationtask)

Description of the problem: I created a code in my experiment so participant can see the percentage (or the sum of their correct responses in a trial). This works locally but not online.

My code is:

```auto
corrTrials = Practicetrials.data['task2prac_key_resp.corr']
msg = "You got %i trials correct out of 4" %(corrTrials.sum())

```

it works locally but not online. I hope to hear from you

---

<div class="post-metadata">

**Author:** ![Becca](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/becca/32/34260_2.png) [@Becca](https://discourse.psychopy.org/u/Becca)\
**Post date:** [February 16, 2022, 6:13pm UTC](https://discourse.psychopy.org/t/sum-trial-feedback-for-block-not-working-online/27451/2 "2022-02-16T18:13:51Z")

</div>

Please share the error message that you get when running online. or the describe the unexpected behaviour if there is no error message.

---

<div class="post-metadata">

**Author:** ![Tin\_Tin](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/tin_tin/32/14611_2.png) [@Tin\_Tin](https://discourse.psychopy.org/u/Tin_Tin)\
**Post date:** [February 16, 2022, 6:18pm UTC](https://discourse.psychopy.org/t/sum-trial-feedback-for-block-not-working-online/27451/3 "2022-02-16T18:18:52Z")

</div>

Dear Becca,

Thank you for your response. It does not have an error message but shows a repeat of the feedback message last presented but in white colour.

Basically I have a self-association task. After each participant press the right key they receive “correct” in green colour. If wrong they receive “incorrect” in red colour. If response takes a while, it receive “too slow”. After 60 trials the participant should receive a message “You have answered 51 out of 60 correct response” from that code locally. But when online the latter code is gone and just a repeat of the last feedback either correct, incorrect or too slow in white colour ink

---

<div class="post-metadata">

**Author:** ![Becca](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/becca/32/34260_2.png) [@Becca](https://discourse.psychopy.org/u/Becca)\
**Post date:** [February 16, 2022, 6:22pm UTC](https://discourse.psychopy.org/t/sum-trial-feedback-for-block-not-working-online/27451/4 "2022-02-16T18:22:19Z")

</div>

> [@Tin\_Tin](#):
>
> `msg = "You got %i trials correct out of 4" %(corrTrials.sum())`

OK thanks for clarifying - could you please try reformatting your code to follow something like this post (which I think may be a similar issue) [Problem to read a code on Pavlovia - #2 by Becca](https://discourse.psychopy.org/t/problem-to-read-a-code-on-pavlovia/27452/2)

---

<div class="post-metadata">

**Author:** ![Tin\_Tin](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/tin_tin/32/14611_2.png) [@Tin\_Tin](https://discourse.psychopy.org/u/Tin_Tin)\
**Post date:** [February 16, 2022, 6:22pm UTC](https://discourse.psychopy.org/t/sum-trial-feedback-for-block-not-working-online/27451/5 "2022-02-16T18:22:30Z")

</div>

I am on the process of sending a picture I am just waiting for the trial. Thank you

---

<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:** [February 17, 2022, 10:18am UTC](https://discourse.psychopy.org/t/sum-trial-feedback-for-block-not-working-online/27451/6 "2022-02-17T10:18:03Z")

</div>

Hello Tin\_Tin,

could it be a problem of string formatting? Do mind showing us the JS-code that PsychoPy used to format your message?

The python formatting

```auto
msg = “my var = %s” % myVar

```

has to be In JS

```auto
msg = “my var = “ + str(myVar)

```

Best wishes Jens

---

<div class="post-metadata">

**Author:** ![Tin\_Tin](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/tin_tin/32/14611_2.png) [@Tin\_Tin](https://discourse.psychopy.org/u/Tin_Tin)\
**Post date:** [February 23, 2022, 2:23am UTC](https://discourse.psychopy.org/t/sum-trial-feedback-for-block-not-working-online/27451/7 "2022-02-23T02:23:29Z")

</div>

Thank you for your help both,

@Becca I adapted your code but unfortunately it is still coming up with an error.  
All I wanted to say in my experiment is the total correct score after each block. Unfortunately, there is still an error. It is working locally but not online

@JensBoelte I have adapted your suggestion too so I added str(myVar) but it is still not working online

My code is below:

nCorr = sum(Practicetrials.data[‘task2prac\_key\_resp.corr’])  
meanRT = average(Practicetrials.data[‘task2prac\_key\_resp.rt’])  
msg = ‘You got’ + str(nCorr) + ‘out of 4 trials’

I hope to hear from you.

---

<div class="post-metadata">

**Author:** ![Tin\_Tin](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/tin_tin/32/14611_2.png) [@Tin\_Tin](https://discourse.psychopy.org/u/Tin_Tin)\
**Post date:** [February 23, 2022, 2:33am UTC](https://discourse.psychopy.org/t/sum-trial-feedback-for-block-not-working-online/27451/8 "2022-02-23T02:33:32Z")

</div>

I have provided the copy of my error message too

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/1/6/169046ba7b4930928f3aaa3ea960cc9a804efc56.jpeg)

---

<div class="post-metadata">

**Author:** ![Becca](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/becca/32/34260_2.png) [@Becca](https://discourse.psychopy.org/u/Becca)\
**Post date:** [February 23, 2022, 8:55am UTC](https://discourse.psychopy.org/t/sum-trial-feedback-for-block-not-working-online/27451/9 "2022-02-23T08:55:04Z")

</div>

what version of psychopy are you using? if you are using something earlier than 2021.2.3 sum might not auto translate

Thanks,  
Becca

---

<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:** [February 23, 2022, 9:22am UTC](https://discourse.psychopy.org/t/sum-trial-feedback-for-block-not-working-online/27451/10 "2022-02-23T09:22:51Z")

</div>

Hello,

if you want to stick to a version prior 2021, take a look in the crib sheet by wakecarter for an online-version of sum

> **[PsychoPy Python to Javascript crib sheet](https://docs.google.com/document/d/13jp0QAqQeFlYSjeZS0fDInvgaDzBXjGQNe4VNKbbNHQ/edit#heading=h.niu1u15qj037)**
>
> PsychoPy version 2020.1.3-2020.2.10Python to JavaScript Crib Sheet Compiled by Wakefield Morys-Carter, Oxford Brookes UniversityPlease share widely and follow Psych\_Stats on twitter. PsychoPy 2020 has an automatic Python to Javascript translation...

Best wishes Jens

---

<div class="post-metadata">

**Author:** ![Tin\_Tin](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/tin_tin/32/14611_2.png) [@Tin\_Tin](https://discourse.psychopy.org/u/Tin_Tin)\
**Post date:** [February 23, 2022, 10:23am UTC](https://discourse.psychopy.org/t/sum-trial-feedback-for-block-not-working-online/27451/11 "2022-02-23T10:23:27Z")

</div>

Hi Becca,

Thank you for getting back to me - I am using Psychopy ver 2021.1.4. Does this mean I cannot give a total of correct trials at the end of each block online because of the version I am using?

If I need to use a different version - does this mean I need to re-program my experiment using another version?

Thanks

---

<div class="post-metadata">

**Author:** ![Tin\_Tin](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/tin_tin/32/14611_2.png) [@Tin\_Tin](https://discourse.psychopy.org/u/Tin_Tin)\
**Post date:** [February 23, 2022, 10:26am UTC](https://discourse.psychopy.org/t/sum-trial-feedback-for-block-not-working-online/27451/12 "2022-02-23T10:26:32Z")

</div>

Hi @JensBoelte

Thank you for sending this through. I am using the v2021.1.4  
I am also very new to coding but will have a look if I can translate sum online with my version.  
Thank you

---

<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:** [February 23, 2022, 11:21am UTC](https://discourse.psychopy.org/t/sum-trial-feedback-for-block-not-working-online/27451/13 "2022-02-23T11:21:22Z")

</div>

Hello Tin\_Tin,

well, it should work in 2021.1.4 but it doesn’t seem to work. You do not have to reprogram your experiment when updating to a new version. Downgrading is more difficult because newer version introduce features that were not available in older versions. So, it might be worth a try to use the current version.

Best wishes Jens

---

<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:** [February 23, 2022, 11:55am UTC](https://discourse.psychopy.org/t/sum-trial-feedback-for-block-not-working-online/27451/14 "2022-02-23T11:55:01Z")

</div>

Hello Tin\_Tin,

according to the manual it is

```auto
nCorr = trials.data['key_resp.corr'].sum()

```

not

```auto
nCorr = sum(trials.data['key_resp.corr'])

```

in PsychoPy.

Best wishes Jens

---

<div class="post-metadata">

**Author:** ![Tin\_Tin](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/tin_tin/32/14611_2.png) [@Tin\_Tin](https://discourse.psychopy.org/u/Tin_Tin)\
**Post date:** [February 23, 2022, 9:11pm UTC](https://discourse.psychopy.org/t/sum-trial-feedback-for-block-not-working-online/27451/15 "2022-02-23T21:11:14Z")

</div>

Dear Sir @JensBoelte

Thank you for your response.

I tried it changing it to adapt your suggestions. Unfortunately, it is still coming up with an error similar to below:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/c/8/c8ec6e95a4257e51ecec17da13f7e80ba72849c1.jpeg)

---

<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:** [February 23, 2022, 9:55pm UTC](https://discourse.psychopy.org/t/sum-trial-feedback-for-block-not-working-online/27451/16 "2022-02-23T21:55:25Z")

</div>

Please could you show the code you’re using?

That error suggests that you are checking the keyboard response before it happens (perhaps in Begin Routine or Each Frame instead of End Routine).

---

<div class="post-metadata">

**Author:** ![Tin\_Tin](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/tin_tin/32/14611_2.png) [@Tin\_Tin](https://discourse.psychopy.org/u/Tin_Tin)\
**Post date:** [February 23, 2022, 10:15pm UTC](https://discourse.psychopy.org/t/sum-trial-feedback-for-block-not-working-online/27451/17 "2022-02-23T22:15:36Z")

</div>

Thanks for taking the time to reply. Please find image below

The msg is located at begin the experiment and code is in begin routine, are you saying that I should move it to end routine?

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/d/2/d216d23fc8507f408c5c099bc16724ce40c35654.jpeg)

---

<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:** [February 23, 2022, 10:21pm UTC](https://discourse.psychopy.org/t/sum-trial-feedback-for-block-not-working-online/27451/18 "2022-02-23T22:21:50Z")

</div>

Do you have any reference in code to .keys (as opposed to .corr and .rt)?

Begin Routine should be fine if this code is in a feedback routine rather than the routine containing the response itself.

---

<div class="post-metadata">

**Author:** ![Tin\_Tin](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/tin_tin/32/14611_2.png) [@Tin\_Tin](https://discourse.psychopy.org/u/Tin_Tin)\
**Post date:** [February 23, 2022, 10:36pm UTC](https://discourse.psychopy.org/t/sum-trial-feedback-for-block-not-working-online/27451/19 "2022-02-23T22:36:34Z")

</div>

Sorry sir, I do not know much about coding so please have patience with me - so what do you mean by .keys?

I am using the .corr because I wanted the code to count the total of correct responses of the participant and provide a feedback about it at the end of the block. So like, “you scored 2 out of 4 trials”.

The codes I had seems to work only locally not Online - am I defining the wrong variables?

Thanks for explaining it to me.

---

<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:** [February 23, 2022, 10:57pm UTC](https://discourse.psychopy.org/t/sum-trial-feedback-for-block-not-working-online/27451/20 "2022-02-23T22:57:45Z")

</div>

Your error message mentions task2prac\_key\_resp.keys which should be the list of keys pressed (and can give an error if you ask information about it when nothing has been pressed).

.corr is the 1 / 0 score and therefore is the one you want. I was wondering if you were referring to .keys in any other code tabs.

[Next page](https://discourse.psychopy.org/t/sum-trial-feedback-for-block-not-working-online/27451.md?page=2)
