psychopy.org | Reference | Downloads | Github

Translating Python to JS for correcting answers from a mouse click and conditions file

URL of experiment: https://run.pavlovia.org/kc71/fok/html/

Description of the problem:
I have an experiment that works great on the desktop. I can’t get the last loop to work online. The last loop is a multiple choice section with 4 boxes to click on. The mouse stores the name of the box it clicked on. There can be up to 40 questions in this section depending on how they did in the first loop. So, the answers are kept in the conditions file. I cannot get the JS script to work no matter what I try. I can see from the results sheet that the experiment is correctly recording the mouse click (box name). I’ve checked my spelling, punctuation, spaces, etc and there’s no typos in the clicked name and correct answer - they match. Right now, it is marking everything as 0, even when the answers match. I did try changing the 1 and 0 to true and false, and it still didn’t work. Any help would be greatly appreciated. Thank you!

This is what is working (Note: mouse is called mouse_recog, and the column of answers in the conditions file is called Currect Lure):

Begin experiment
corrrecog = ''

Each frame

if mouse_recog == CorrectLure:
     corrrecog = 1
else:
     corrrecog = 0

End Experiment
thisExp.addData('CorrectRecog', corrrecog)

This is what I have for JS script right now:

Begin Experiment
corrrecog = '';

Each Frame

if (mouse_recog.clicked_name == CorrectLure) {
     corrrecog = 1;
}
else {
     corrrecog = 0;
}

End Experiment
psychoJS.experiment.addData('CorrectRecog', corrrecog);

Ok, so I made a massively silly mistake. The code above works perfectly when you put it in the correct section. Because I have it in every frame instead of end of routine, it’s not working. The mouse_recog.clicked_name doesn’t register until the end of the routine. I moved the code to the end of routine box, and now it works great.