clearEvents() Py to JS

Hi,

I’m having some trouble finding a JS equivalent for the Python code I’m using. I have been using event.clearEvents(‘keyboard’) at the Begin Routine stage in the builder and it is working as intended. I have let the Auto → JS translate the code to event.clearEvents(“keyboard”); however when trying to run the experiment on Pavlovia I receive the following error message:

TypeError: undefined is not an object (evaluating ‘event.clearEvents’)

Would anyone be able to give advice on why this error is occurring?

Have you put event=psychoJS.eventManager; in code_JS (see my crib sheet)?

I’m not sure “keyboard” is recognised by event.clearEvents()

I’ve added thisExp=psychoJS.experiment; and event=psychoJS.eventManager; to code_JS and also changed event.clearEvents(‘keyboard’) to event.clearEvents() which has resolved the error, thanks!

I’m now having an issue recognising a correct/incorrect response. I have set feedback to display whether the participant’s response was correct or incorrect, however it keeps only displaying ‘incorrect’ on Pavlovia. I am using auto>JS to turn

if StimResp_KeyResp.keys == CorrAns:
StimFeedback = 'Correct’
else:
StimFeedback = 'Incorrect’

Trials.addData(‘CorrectAnswer’, StimFeedback)

to

if ((StimResp_KeyResp.keys === CorrAns)) {
StimFeedback = “Correct”;
} else {
StimFeedback = “Incorrect”;
}
Trials.addData(“CorrectAnswer”, StimFeedback);

The python version is working in PsychoPy

Try

if CorrAns in StimResp_KeyResp.keys: