Specifying a response from a conditions file and saving responses

Dear Community,
my current experiment consists of a lexical decision task, where pressing the right arrow indicates a non-word and pressing the left arrow key indicates a word. Whether a presented word stimulus is a word or a non-word is specified in a conditions file, with a variable ‘correctResponse’, defined as either left or right.
After each response, participants are also supposed to receive feedback, with a text saying either ‘right’ or ‘wrong’ and their responses should be saved to the output file.
Currently, none of this is working properly, meaning that responses are not saved and the feedback ‘correct’ is given for any response.
My impression is that the correctResponse variable from the conditions file and the key response aren’t matched properly in the script, possibly because in the conditions file the correctResponse is specified as a string.
I have tried the following lines, but received a syntax error (I have zero coding experience). My questions are a) whether this makes sense at all and if not what else I can do, and b) if it does make sense, how can I put this into correct Js syntax?

practice[correctResponse(‘left’)] == 0;
practice[correctResponse(‘right’)] == 1;

probeResponse1.keys(‘left’) == 0;
probeResponse1.keys(‘right’)== 1;

Thank you so much in advance! :))

If you have a keyboard component and you set the correct answer as correctResponse then the score should be probeResponse1.corr

Hi wakecarter, thanks for your response! Unfortunately it does not record the response, that’s why i have tried inserting the above lines. Do you have any suggestions what else i might try?


Please could you show screenshots of your keyboard component. If you have a simple keyboard response then it is more reliable to use a component than code.

Thank you for looking into it! I’m trying to debug in the online Js now, because the synchronisation between builder and pavlovia really doesn’t work for me. I hope the screenshot helps. Again, many thanks!

If synchronisation from Builder doesn’t work for you, then I would recommend concentrating on fixing that.

Are your local files in a cloud drive?

In what way does it not work for you?

I would rather like to focus on getting the responses saved in the output. Can you tell me if the keyboard component is set up correctly? What about the lines of code that I thought about adding?
Thank you and have a good weekend!

In that case I’m not going to be able to help you much further, I’m afraid.

I note that in your code you are saving the keys pressed to the data file but not the score.

Thank you, I’ve had a look into this, but the issue is that the keys pressed aren’t saved either. In fact, no responses at all are being saved. Is there any further advice about what I can do to get any response data saved?

Hi Jasmine,

I really would recommend trying to fix the sync issue first as Wake suggests. Storing correct answers and giving feedback is very simple in PsychoPy builder, with minimal need for code. It will probably take much less time to fix the sync issue and then check why accuracy isn’t storing than to try and hack the Javascript code (which also might be difficult for future lab members to work with).

Can you tell us more about the sync issue - what seems to be happening there?


1 Like

Hi Becca, thanks for looking into this as well! I have followed your recommendation and created a new experiment that I will now try to debug from the offline PsychoPy.
The issue that I usually have with this is that when synchronising changes PsychoPy doesn’t seem to recognise that the experiment already exists online and I have to create a new one with the same name. That can be quite confusing and time-consuming. Further I find that fixing certain errors can be done a lot faster in the online Js, rather than through the builder. For example, now I am receiving an unknown image resource error, even though the png file is located in the html/resources folder and this path is also specified in the builder component.

Please recreate your experiment again with nothing in the Online Output Path. The html folder doesn’t work with the latest version of PsychoPy

Also, make sure you aren’t saving your local files on a cloud drive.

Hello Wakecarter, thank you so much for the patient and quick support with this! I have tried to recreate the project, but it is indeed somehow always drawing the resources from a previous project and I have not found a way to delete the repository from github. I have therefore created a whole new pavlovia account and created this as the first and only project there. However, somehow it is still linking the resources with my previous github account. I am really confused and don’t understand why this is happening.

The issue is with local git files and hidden folders which is why I often recommend moving the psyexp file and resources to a clean local folder. Then reopen in PsychoPy and sync.

Just to follow up here - if possible try to show hidden files and delete the .git (it can be annoying in the long run to have lot’s of hidden .gits lying around)

Update: I have attempted to add the code lines
expName: expName,
expInfo: expInfo,
resources: […

into the ‘before experiment’ ta, and removed the other psychoJS.start lines. Now the experiment is stuck in initialising with the error “Uncaught ReferenceError: Cannot access ‘psychoJS’ before initialization”

Hi Jasmine,

Yes I would advise not to try adding that code snippet to inside you experiment, that will try to launch your experiment twice and it will cause complication. Is your experiment pushing and syncing to pavlovia ok now?


Hi Becca, unfortunately I’m still getting error messages when trying to sync and I have to delete the experiment from my dashboard each time and then upload it anew. But then the resources are uploaded in a very strange folder structure and I have to upload each resource individually into the correct folder to solve the resource error… but then I am receiving more errors…
It has really been easier to directly change the .js code in the html folder and I already got a lot further in this way. Is there really no way you could help me to get the responses to save by debugging the code?

Hi Jasmine,

Please can you share the error messages that you get when trying to sync? Then we can offer support to try and fix that problem.

Sorry, but I am less familiar with pure JavaScript code and we really do advise against directly editing it unless you are confident with JavaScript syntax. it really is better that we fix the root cause of the issue by trying to figure out your sync error.


The first error I usually encounter when trying to sync. By deleting and uploading again, I can get it to upload, but when trying to pilot, I receive the 403 error.
When then deleting and uploading again I can get the piloting to ‘start’, but then encounter the undefined name error.

Before when working on the code I was able to run the entire experiment, with pretty much the only issue of not having the responses save.