TypeError: cannot set property 'color' of undefined in pavlovia

URL of experiment: Pavlovia (experiment is in Dutch but just keep pressing SPACE)

Description of the problem: I am having trouble creating a checkbox that syncs to Pavlovia. I am currently using a polygon called Implausible to represent a white square, that I use the following Python code for to turn black when clicked:

Begin routine

Checkboxes = [Implausible]
Clicked = []
for box in Checkboxes:
    box.color = "white"

Each frame

for box in Checkboxes:
    if mouse.isPressedIn(box) and box.name not in Clicked:
        box.color = "black"
        Clicked.append(box.name)

This works without any problems on my laptop. Unfortunately, this doesn’t work in JavaScript. I have rewritten the automatic JavaScript code to this:

Begin routine

let Checkboxes = [Implausible];
let Clicked = [];
white = new util.Color([1, 1, 1]);
black = new util.Color([-1, -1, -1]);

for(var index=0; index<=Checkboxes.length; index++){
    Checkboxes[index].color = white;
};

Each frame

for(var index2=0; index2<=Checkboxes.length; index2++){
    if (mouse.isPressedIn(Checkboxes[index2])&&Clicked.includes(Checkboxes[index2].name)==false){
        Checkboxes[index2].color = black;
        Clicked.push(Checkboxes[index2].name);
    }

};

I unfortunately keep getting the error that I cannot set the property color of the polygon (TypeError: cannot set property ‘color’ of undefined). In the crib sheet it says that “The issue is likely to be with the variable or array or variable for which you are trying to find property x, rather than any issue with finding property x in general”. However, when trying to troubleshoot, the issue appears to be in the code rather than an issue with the stimulus. Has anyone had a similar issue, and do you know how to solve it? Any help would be greatly appreciated!

Hi,

I think I may have a similar kind of issue, although the TypeError is not exactly the same : Pavlovia -- Checkbox code generates a Type Error Cannot read properties of undefined (reading 'status')