Pavlovia TypeError: Cannot read properties of undefined (reading 'Keyboard')

Hi everyone. I’ve been working on an experiment that I really need to get out soon. It works perfectly in PsychoPy, but the moment I try to pilot it on Pavlovia I get the following message:
TypeError: Cannot read properties of undefined (reading ‘Keyboard’)
I’ve tried inspecting the experiment, and this is what I got:
Screenshot 2022-05-04 213144

I’m sorry, I’m terribly new to this so I’m a bit at a loss and unsure what else I should add. I found other posts on here about things being undefined, but none of them really gave me a solution.
It was mostly built in the builder, with 4 code components:

  1. To let the experiment branch depending on whether a participant consents to take part: if they consent (by pressing Y), they’ll get sent to the experiment, if they don’t consent (by pressing N), they’ll skip the experiment loop and be sent to a goodbye message
  2. To determine which conditions file they get in the learning routine: this is determined by the participant number they fill in, so no keyboard response needed there
  3. To determine which conditions file they get in the test routine: this is the same as the previous code. No keyboard involved
  4. To let a test sound play when they press T: before they get exposed to the actual audio stimuli, I let them test their device’s volume by pressing T. Then they can adjust their volume accordingly, and press SPACE to continue to the rounds with the actual audio stimuli. This is the one whose programming I am the most unsure of, because well… I tried something and it just happened to work. Here’s the code, if you’re curious:

Begin Experiment Tab:

var core = import("psychopy/core");
var sound = import("psychopy/sound");
function playSound() {
    var testaudio;
    testaudio = new sound.Sound("testaudio.wav", {"secs": 1});
    testaudio.setVolume(1);
    testaudio.play();
    core.wait(0.3);
}

Each Frame Tab:

if (psychoJS.eventManager.getKeys({"keyList": ["t"]})) {
    playSound();
}

Those code components were first written in python, but later converted to JS, as there was an issue with initialising the experiment at first.
I’m just at a loss because I’m not sure where it even expects Keyboard to be defined: it let me add all those keyboard components in the builder and now it starts complaining in Pavlovia, then why let me add them in the first place?! (this is me just venting).

Any help would be hugely appreciated, I really need to get this experiment out soon.

What is line 185 of SAVEMEEEEEE.js? (click on the link in the error message)

I can’t see your Begin Experiment tab working. Have a look at:
https://psychopy.org/online/psychoJSCodingDebugging.html

and

Line 185 is

consent_resp = new core.Keyboard({psychoJS: psychoJS, clock: new util.Clock(), waitForStart: true});

in the context of:


It’s the routine that asks people whether they consent to participating in the experiment. (so the first code component I described in my original post)

I will have a look at your links tomorrow morning (it is 10 pm here and I’m exhausted). Thank you for responding :slight_smile:

Your error is because “core” is undefined online.

Is line 185 something you wrote or was it created in Builder from a keyboard component?

from a keyboard component

I don’t know if it is any use, but I made the consent routine using this video from the official psychopy youtube channel:How to Make Branched Experiments in PsychoPy

I think that you’ve broken keyboard components by adding var core = import("psychopy/core");. Where did that code come from?

I gotta be honest, I have no clue anymore.
I know it was from a post like this: How to play and repeat stimuli after a manual click , but it had that var code and var sound in front of it, but I can’t seem to find said post anymore.
Or rather, this was how it originally was in python:

import psychopy.core as core
import psychopy.sound as sound

def playSound():
    testaudio = sound.Sound('testaudio.wav', secs = 1)
    testaudio.setVolume(1)
    testaudio.play()
    core.wait(.3)

and this is what it became in JS:

import * as core from 'psychopy/core';
import * as sound from 'psychopy/sound';
function playSound() {
    var testaudio;
    testaudio = new sound.Sound("testaudio.wav", {"secs": 1});
    testaudio.setVolume(1);
    testaudio.play();
    core.wait(0.3);
}

which caused trouble because of the asterisks, and so I ended up with the var core that you see now (with some help from a friend who knows a little more than me)

I’ve honestly been considering just throwing the audio testing routine out and get my participants to check their audio another way, because I keep suspecting this routine is the cause of all my woes.

Perhaps you should direct your friend to my crib sheet.

Use Builder components to create sounds that work online. Once created they can be controlled in code.

Thank you for your help. It’s a long story, but we’ve managed to solve it in the meantime. Again, thanks for your help!