psychopy.org | Reference | Downloads | Github

TypeError when running experiment online

URL of experiment: https://gitlab.pavlovia.org/slorimer02/temp (permissions set to internal)

Description of the problem: I’m currently trying to get an experiment up and running on Pavlovia. The task works perfectly when run from PsychoPy. I’m currently getting the following error and don’t know where I’m going wrong.

  • TypeError: mouse_2.isPressedIn is not a function

which relates to the following routine and code component.

Begin experiment
segments_1 = [polygon1, polygon2, polygon3, polygon4, polygon5, polygon6, polygon7, polygon8, polygon9, polygon10, polygon11, polygon12, polygon13, polygon14, polygon15, polygon16, polygon17, polygon18, polygon19, polygon20]

Begin routine
for (var i = 0; i < segments_1.length; i++)
{
segments_1[i].fillColor = ‘white’;
segments_1[i].lineColor = ‘black’;
}
resetSegments = false;

Each frame
var segmentIndex;

for (var i = 0; i < segments_1.length; i++)
{
if (mouse_2.isPressedIn(segments_1[i]))
{
segmentIndex = i;
resetSegments = true;
}
}

if (resetSegments)
{
for (var i = 0; i < segments_1.length; i++)
{
segments_1[i].fillColor = ‘white’;
}
resetSegments = false;
}

if (segmentIndex != null)
{
for (var i = 0; i < segmentIndex; i++)
{
segments_1[i].fillColor = ‘black’;
}
}

Hi @slorimer, the isPressedIn function is not currently available in the PsychoJS library. However, here is an example of how to code your task manually to check if a mouse is clicked in an object.

msg = '';
if (mouse.getPressed()[0] === 1) { // If left mouse button pressed 
  clickable = [SomeObject, AnotherObject];  // clickable stim
  for (const obj of clickable) {  // for each clickable stim, check if it contains the mouse
    if (obj.contains(mouse)) {
      msg = "You have clicked object: " + obj.name;
    }
  }
}