TypeError: undefined is not an object (evaluating 'win._psychoJS')

URL of experiment: Pavlovia

Description of the problem:

I have created a task that requires participants to place words in boxes by a clicking and dragging. When the participant places a word in the correct box, they get 1 point, this appears at the top of the screen. This all works perfectly in builder, however, when I sync this to Pavlovia I get the below error when trying to run it.

I have added custom code in order to get the above to work, whether the issue lies there, I am unsure.

Thanks for the help!

It’s how you’re defining “score_text” in a code block.

The best solution in my opinion would be to make an actual text component in the builder for score_text and either update it’s content (score_text.text = 'Score: ${score}') or its visibility (score_text.autoDraw(false) at the beginning of the routine and score_text.autoDraw(true) when you want it to appear).

The basic issue is that you define it this way:

    score_text = new visual.TextStim(psychoJS.window, 
    {"text": `Score: ${score}`, 
    "pos": [0, 0.4], 
    "height": 0.05, 
    "color": "black"});

but if you really want to define it in a code block, it needs to look like this:

    score_text = new visual.TextStim(
    {"win":psychoJS.window, //this is the important change
    "text": `Score: ${score}`, 
    "pos": [0, 0.4], 
    "height": 0.05, 
    "color": "black"});

But again, I think it’d be easier to just make it a normal text component in the builder and control its content or appearance with the code component.

Thank you so much for the help, this worked great, I chose to do the option you suggested the least, purely as it was the easier one for me to do with my lack of coding knowledge.