psychopy.org | Reference | Downloads | Github

Keyresponse.stop is not a function

URL of experiment: Pavlovia
Git: https://gitlab.pavlovia.org/knfernandez/risky-gambles/blob/master/gambleTask.js

Description of the problem:
When I add a keyboard response that does not force the end of a routine in the builder, I receive the following error:

  • TypeError: gmKR.stop is not a function

That code refers to this block here:

  return function () {
    //------Ending Routine 'gamTrial'-------
    for (const thisComponent of gamTrialComponents) {
      if (typeof thisComponent.setAutoDraw === 'function') {
        thisComponent.setAutoDraw(false);
      }
    }
    psychoJS.experiment.addData('gmKR.keys', gmKR.keys);
    if (typeof gmKR.keys !== 'undefined') {  // we had a response
        psychoJS.experiment.addData('gmKR.rt', gmKR.rt);
        }
    
    gmKR.stop();
    return Scheduler.Event.NEXT;
  };
}

I have a keyboard response (also created with the Bulider) before this keyboard response, so it does not appear that there is a problem with keyboard components in general. But, it seems related to the key press not ending the routine/ allowing a window of time to respond.

Things I have tried:
-Updating to the newest version of PsychoPy.
-Deleting and re-adding the keyboard component
-Switching between using duration or time to end the key response window
-Editing the code in the code element that refers to the keyboard response.
For this last item, I thought perhaps I was referencing the keyboard responses to display an image incorrectly (perhaps the proper syntax had been updated) but all of those changes only resulted in other errors.

I did notice in the js code, however, that routineTimer.reset() does not follow after gmKR.stop; is it possible that this is creating the error? How would I fix this while still being able to use the Builder? Since the Builder is “creating the code” where Pavlovia is pointing to an error, I am not sure what else I can try.

I stand corrected- I removed the keyboard responses that were resulting in the .stop error and relied on timing for the remainder of the routines. When I do that, everything works. I still have one keyboard response that works when I do this.

In addition, I tried adding one of the keyboard responses back after removing the ones creating errors, but this time made it “end routine”. The error persists for the second (recently re-added) keyboard response, but not for the first one! I am not quite sure what that tells me, except that there is something going on specifically with keyboard responses.

Could you share the GitLab repo of your experiment? This page explains how. My username is: tpronk

I have added your username to the project. Please let me know if I need to make the project public or if I need to assign you a different role to fully access the GitLab.

Yeah, I need a different role. Probably developer or maintainer would do the trick

I updated your role to developer.

I can’t find gmKR, but there is a gamKR and gamInKR. What’s the new name of the component that gave this error?

Sorry, it should be gamKRwhich gives the error. I must have renamed it slightly when I tried deleting and re-adding it.

No worries :). I reproduced your issue and took a look in the code. I noticed one thing there that could cause issue: in the code component setGam, tab Begin Experiment, there is a line:
gamKR = psychoJS.eventManager.getKeys();

That replaces the variable name used for the keyboard component named gamKR by whatever is returned by psychoJS.eventManager.getKeys(); (an associative array).

Later on, upon a response, PsychoJS tries to stop the KeyboardComponent, by calling gamKR.stop(), but at that point gamKR isn’t a KeyboardComponent anymore, so this function doesn’t exist, and an error is thrown

Thank you, that solved it!

1 Like