| Reference | Downloads | Github

Code component runs locally but not on Pavlovia

Hi there,

I’m trying to create an experiment in which participants are deciding between two probabilities and two monetary values. They click the key ‘A’ to choose the option on the left (the probability on the top left and the monetary value on the bottom left) and ‘K’ for the option on the right (the probability on the top right and the monetary value on the bottom right):


Based on their response, we’re trying to provide feedback by bolding the options on the left if ‘A’ is clicked and bolding the options on the right if ‘K’ is clicked.

In order to do this I created another routine after the choice is made where the same 2 probabilities and 2 monetary values show up (theres no key component here but a code component for the bolding part) I pasted the following code in the Begin Routine section of the code component:

keyPressed = event.getKeys()[0]
if keyPressed == ‘a’:
P1_2.setFont(‘Arial Black’)
M1_2.setFont(‘Arial Black’)
P2_2.setFont(‘Arial Black’)
M2_2.setFont(‘Arial Black’)

The code type is set to auto → JS. It runs perfectly fine when I’m running the study locally on psychopy however when I sync it with Pavlovia and try to run it online I face this error:

-TypeError: Cannot read property ‘getKeys’ of undefined.


I would really appreciate if anyone has any ideas on how this can be fixed or any insight.


You need to define event in code_JS

Search for my crib sheet

Thank you so much for your help @wakecarter. I followed the steps outlined in the crib sheet.