TypeError: Cannot read property 'addChild' of undefined

Interesting. I see you have that statement, or variants of it, several times throughout the code, and you’re saying it works fine on other trials. Looking at the other instances of that code, my best guess is that rec_score is not drawn before this is called. That is, the other three times this “contains” setup is used, the object you’re checking has “setAutoDraw = true” on an earlier line in the every-frame code for their respective trials. (If you do a search for “contains” in the js code you will see what I mean: https://gitlab.pavlovia.org/Wake/ebbinghaus-darts/blob/master/html/ebbinghaus%20darts.js). So, my guess is that because rec_score hasn’t been drawn yet, it can’t work out “contains” because “contains” requires the shape to be present on the screen.

The solution would be either to make sure rec_score is drawn before that line of code, or to add an additional check to the else statement to make sure it only gets to the contains statement if the shape has been drawn:

mouseloc = mouse.getPos();
    if ((((mouseloc[0] === mouserec[0]) && (mouseloc[1] === mouserec[1])) && (inflight < 2))) {
    } else if (rec_score.autoDraw === true){
        if (rec_score.contains(mouse)) {
            mouserec = mouseloc;
            continueRoutine = false;
        } else {

This is mostly an educated guess, but it seems like the most likely candidate given that this is the only instance of that code that has trouble.

edit: Misnamed the autoDraw variable.