# TypeError: Cannot read property 'clearEvents' of undefined\*

**URL:** <https://discourse.psychopy.org/t/typeerror-cannot-read-property-clearevents-of-undefined/20693>\
**Category:** Online experiments\
**Created:** [February 23, 2021, 12:42am UTC](https://discourse.psychopy.org/t/typeerror-cannot-read-property-clearevents-of-undefined/20693 "2021-02-23T00:42:19Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Astevens07](https://avatars.discourse-cdn.com/v4/letter/a/3be4f8/32.png) [@Astevens07](https://discourse.psychopy.org/u/Astevens07)\
**Post date:** [February 23, 2021, 12:42am UTC](https://discourse.psychopy.org/t/typeerror-cannot-read-property-clearevents-of-undefined/20693/1 "2021-02-23T00:42:19Z")

</div>

URL of experiment: [https://run.pavlovia.org/Aryanestevens/pierce-19a-dec-2020](https://run.pavlovia.org/Aryanestevens/pierce-19a-dec-2020)

Description of the problem: Hi there! I am a complete novice when it comes to any kind of coding, so please bear with me. My experiment is crashing at a certain point and I’m not sure how to proceed. This is the error message I’m receiving:

- **TypeError: Cannot read property ‘clearEvents’ of undefined**

I’ve tried editing the JavaScript portion of the code to read “psychoJS.eventManager” (instead of “events.”), to no avail. The part of the experiment where things are going wrong is a section where I’ve added code in order to allow participant responses to appear on screen (the code for which I found by scouring the forum). I have also reviewed the PsychoPy crib sheet and I suspect that the solution may be there, but I can’t be sure. Any ideas? Thanks in advance 🙂

---

<div class="post-metadata">

**Author:** ![thomas\_pronk](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/thomas_pronk/32/9531_2.png) [@thomas\_pronk](https://discourse.psychopy.org/u/thomas_pronk)\
**Post date:** [February 25, 2021, 11:40am UTC](https://discourse.psychopy.org/t/typeerror-cannot-read-property-clearevents-of-undefined/20693/2 "2021-02-25T11:40:17Z")

</div>

Hey! I’ve got a general suggestion: to get a better grasp on what’s going wrong it could be useful to learn a couple of debugging tricks. This experiment contains links to tutorials about error handling and writing debug output: [Thomas Pronk / assignment\_stroop · GitLab](https://gitlab.pavlovia.org/tpronk/assignment_stroop/)

---

<div class="post-metadata">

**Author:** ![Astevens07](https://avatars.discourse-cdn.com/v4/letter/a/3be4f8/32.png) [@Astevens07](https://discourse.psychopy.org/u/Astevens07)\
**Post date:** [February 25, 2021, 8:34pm UTC](https://discourse.psychopy.org/t/typeerror-cannot-read-property-clearevents-of-undefined/20693/3 "2021-02-25T20:34:49Z")

</div>

Awesome, thank you! I will check this out.

---

<div class="post-metadata">

**Author:** ![sydperry14](https://avatars.discourse-cdn.com/v4/letter/s/f05b48/32.png) [@sydperry14](https://discourse.psychopy.org/u/sydperry14)\
**Post date:** [March 2, 2021, 1:15am UTC](https://discourse.psychopy.org/t/typeerror-cannot-read-property-clearevents-of-undefined/20693/4 "2021-03-02T01:15:07Z")

</div>

I’m having the same issue. Was there ever a solution found?

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [March 2, 2021, 6:53am UTC](https://discourse.psychopy.org/t/typeerror-cannot-read-property-clearevents-of-undefined/20693/5 "2021-03-02T06:53:27Z")

</div>

Please could you show the code where you clear events?

---

<div class="post-metadata">

**Author:** ![sydperry14](https://avatars.discourse-cdn.com/v4/letter/s/f05b48/32.png) [@sydperry14](https://discourse.psychopy.org/u/sydperry14)\
**Post date:** [March 2, 2021, 1:34pm UTC](https://discourse.psychopy.org/t/typeerror-cannot-read-property-clearevents-of-undefined/20693/6 "2021-03-02T13:34:21Z")

</div>

![key.clearEvents](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/b/3/b3df344a40e17986cf86847fee2a3ac280969354.png) ![psychoJS.clearEvents](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/3/5/351f9eebf93e2f30895d8128bbf78f138faef61b.png)

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [March 2, 2021, 1:37pm UTC](https://discourse.psychopy.org/t/typeerror-cannot-read-property-clearevents-of-undefined/20693/7 "2021-03-02T13:37:38Z")

</div>

You are trying to clear events from a keyboard response that hasn’t yet started. Have a look at my crib sheet for how to write clear events. I think it’s just event.clearEvents() with event properly defined in code\_JS

---

<div class="post-metadata">

**Author:** ![sydperry14](https://avatars.discourse-cdn.com/v4/letter/s/f05b48/32.png) [@sydperry14](https://discourse.psychopy.org/u/sydperry14)\
**Post date:** [March 2, 2021, 1:44pm UTC](https://discourse.psychopy.org/t/typeerror-cannot-read-property-clearevents-of-undefined/20693/8 "2021-03-02T13:44:05Z")

</div>

I’m sorry, I’m very new to PsychoPy and I’m not a coder. I’m also now on a time crunch to get my experiment up and running. Would be able to provide more simplified instructions by chance? Also, when I had it as “event.clearEvents” it gave me an error for that as well where its said it was undefined. It was working great for a few days then a made one minor time change and it’s popping up with this error.

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [March 2, 2021, 1:58pm UTC](https://discourse.psychopy.org/t/typeerror-cannot-read-property-clearevents-of-undefined/20693/9 "2021-03-02T13:58:37Z")

</div>

I’m now on my laptop so I can check my crib sheet

Add **event=psychoJS.eventManager;** to a Begin Experiment tab of a JS only code component

Then **event.clearEvents()** should work.

---

<div class="post-metadata">

**Author:** ![sydperry14](https://avatars.discourse-cdn.com/v4/letter/s/f05b48/32.png) [@sydperry14](https://discourse.psychopy.org/u/sydperry14)\
**Post date:** [March 2, 2021, 3:28pm UTC](https://discourse.psychopy.org/t/typeerror-cannot-read-property-clearevents-of-undefined/20693/10 "2021-03-02T15:28:25Z")

</div>

That worked great! Thank you so much!
