Sum trial feedback for block not working online

URL of experiment: NegativeSelfAssociation [PsychoPy]

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:

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

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

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

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

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

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

msg = “my var = %s” % myVar

has to be In JS

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

Best wishes Jens

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.

I have provided the copy of my error message too

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

Thanks,
Becca

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

Best wishes Jens

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

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

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

Hello Tin_Tin,

according to the manual it is

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

not

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

in PsychoPy.

Best wishes Jens

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:

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).

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?

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.

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.

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.