TypeError: Cannot read property 'map' of undefined

URL of experiment:

Description of the problem:
TypeError: Cannot read property ‘map’ of undefined
Screenshot of Javascript console after error:

I’m pretty sure this has to do with the pesky slider which I’ve been debugging, but I’m out of ideas. I think I need to make the slider marker and rating exist earlier than they do so that they’re not undefined when “map” gets called, but I don’t know when that’s happening or how to make them exist even earlier.

Thanks,
Jon

Update: after examining javascript console, I think it’s an issue with the color of the text stimuli? They’re “white”… I tried replacing the colors with $(1,1,1), and I got
the colorspace must be RGB for a named color
so I’m switching it back…

Have a look at my crib sheet for a suggestion of how to define colours.

Best wishes,

Wakefield

1 Like

Thank you! This fixed the problem.

Hey Wakefield,

is there anything else I can do if I get this error? None of the solutions I found worked in my case… I want to ask the participants if they saw an image stimulus and they can click on YES or NO in a box. If they click YES, they are asked what was on the picture they saw and when they click on NO, I want to skip the “what was on the picture” routine. But I get the “cannot read property ‘map’ of undefined” error even before the screen is drawn. So it is not appearing when the mouse is clicked too early, neither do I define any colors in a code component. (which are the problems I found in the forum) And I also checked your crib sheet, but moving the code component below the answer boxes did not fix the problem and I am not even sure if the if code component is the problem because I get the same error, when excluding that code component.

This is the link to my experiment:

Please could you show screenshots of the relevant routines and code components?

yes, of course!


and this is the code in the js files:
// Initialize components for Routine “gesehen”
gesehenClock = new util.Clock();
jaBox = new visual.Rect ({
win: psychoJS.window, name: ‘jaBox’,
width: [0.25, 0.1][0], height: [0.25, 0.1][1],
ori: 0, pos: [(- 0.3), 0],
lineWidth: 1, lineColor: new util.Color([(- 1), (- 1), (- 1)]),
fillColor: new util.Color([0, 0, 0]),
opacity: 1, depth: 0, interpolate: true,
});

neinBox = new visual.Rect ({
win: psychoJS.window, name: ‘neinBox’,
width: [0.25, 0.1][0], height: [0.25, 0.1][1],
ori: 0, pos: [0.3, 0],
lineWidth: 1, lineColor: new util.Color([(- 1), (- 1), (- 1)]),
fillColor: new util.Color([0, 0, 0]),
opacity: 1, depth: -1, interpolate: true,
});

gesehen_frage = new visual.TextStim({
win: psychoJS.window,
name: ‘gesehen_frage’,
text: ‘default text’,
font: ‘Arial’,
units: undefined,
pos: [0, 0.4], height: 0.035, wrapWidth: undefined, ori: 0,
color: new util.Color(‘white’), opacity: 1,
depth: -2.0
});

ja = new visual.TextStim({
win: psychoJS.window,
name: ‘ja’,
text: ‘Ja’,
font: ‘Arial’,
units: undefined,
pos: [(- 0.3), 0], height: 0.035, wrapWidth: undefined, ori: 0,
color: new util.Color(‘black’), opacity: 1,
depth: -3.0
});

nein = new visual.TextStim({
win: psychoJS.window,
name: ‘nein’,
text: ‘Nein’,
font: ‘Arial’,
units: undefined,
pos: [0.3, 0], height: 0.035, wrapWidth: undefined, ori: 0,
color: new util.Color(‘black’), opacity: 1,
depth: -4.0
});

mouse = new core.Mouse({
win: psychoJS.window,
});
mouse.mouseClock = new util.Clock();

[…]

if (jaBox.contains(myMouse)) {
    stim_seen = true;
} else {
    if (neinBox.contains(myMouse)) {
        stim_seen = false;
        if ((gesehen_frage.text === "Haben Sie einen roten Rahmen gesehen?")) {
            given_answer1 = "nicht gesehen";
        } else {
            if ((gesehen_frage.text === "Haben Sie einen blauen Rahmen gesehen?")) {
                given_answer2 = "nicht gesehen";
            }
        }
    }
}

// *mouse* updates
if (t >= 0.0 && mouse.status === PsychoJS.Status.NOT_STARTED) {
  // keep track of start time/frame for later
  mouse.tStart = t;  // (not accounting for frame time here)
  mouse.frameNStart = frameN;  // exact frame index
  
  mouse.status = PsychoJS.Status.STARTED;
  mouse.mouseClock.reset();
  prevButtonState = mouse.getPressed();  // if button is down already this ISN'T a new click
  }
if (mouse.status === PsychoJS.Status.STARTED) {  // only update if started and not finished!
  let buttons = mouse.getPressed();
  if (!buttons.every( (e,i,) => (e == prevButtonState[i]) )) { // button state changed?
    prevButtonState = buttons;
    if (buttons.reduce( (e, acc) => (e+acc) ) > 0) { // state changed to a new click
      // check if the mouse was inside our 'clickable' objects
      gotValidClick = false;
      for (const obj of [jaBox, neinBox]) {
        if (obj.contains(mouse)) {
          gotValidClick = true;
          mouse.clicked_name.push(obj.name)
        }
      }
      if (gotValidClick === true) { // abort routine on response
        continueRoutine = false;
      }
    }
  }
}

Do I have to fix the arguments that were initialized with “undefined”? In builder I had “units = from exp settings”… might that be a problem?

Oh now it works. I noticed, that I used the wrong name for the mouse :woman_facepalming: with “contains(mouse)” instead of “contains(myMouse)” it works

1 Like