Feedback after block wont translate to JavaScript

PsychoPy version : 3.0.3
What are you trying to achieve?:
I want the participants to see their performance (% trials correct) after each block, but the automatic translation from Python to Java comes up as syntax error.

On Psychopy, the feedback wors perfect. However, in order to upload it to Pavlovia, I need to have the coding on Java, yet on the box is says “syntax error” (see the image).
I’m new to coding so I’m not too sure why it is not translating.

Thanks for the help!

Hi,

You can’t use this method of formatting strings online. Use “text” + str(variable)

Please do have a look at my crib sheet in the pinned post.

Is this the only problem? There is no sum() equivalent in JS.
@Sarah_Soto, I’ve been there and the only way I found to solve this issue, was to make my own custom variables, increment them every time my participant gave an accurate response and then at the of the block display the accuracy. Then with a conditional loop, after the end of the block (e.g. 80 trials) I reset the Accuracy so that it starts again from 0 for the next block. If you think this could also be done in your case, do let me know to post the code snippets.

1 Like

You’re correct, though sum() can be sorted in code_JS with

sum = function (arr) {
return arr.reduce((a,b)=>a+b)
}
OR
sum = (arr) => arr.reduce((a,b)=>a+b)

Hi, Thanks for the answer!
Yet again, I’m very new to coding in Java, so how would I get the “sum = (arr) => arr.reduce((a,b)=>a+b)” with the run results?

Please take a look at my crib sheet if you haven’t already.

The code I mentioned goes into code_JS in the first routine so that when you want to sum you can just use sum() in Python as normal and have it auto translate.

Hi @phoenix, could you please post the code snippets?
Many thanks