# \[SOLVED\] Cluttered Corridors - event.message error

**URL:** <https://discourse.codecombat.com/t/solved-cluttered-corridors-event-message-error/21086>\
**Category:** Level Help\
**Created:** [April 19, 2020, 8:44pm UTC](https://discourse.codecombat.com/t/solved-cluttered-corridors-event-message-error/21086 "2020-04-19T20:44:26Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![xiaoming](https://avatars.discourse-cdn.com/v4/letter/x/a6a055/32.png) [@xiaoming](https://discourse.codecombat.com/u/xiaoming)\
**Post date:** [April 19, 2020, 8:44pm UTC](https://discourse.codecombat.com/t/solved-cluttered-corridors-event-message-error/21086/1 "2020-04-19T20:44:26Z")

</div>

Hi, when I execute the codes, it gave me error:

 ![image](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/2/2c5e4d80caa0f47adbe7421c59058ed6493987f4.jpeg)

and here are my codes:

```python
def onHear(event):
    word = event.message.toLowerCase()
    # Convert the word to lower case.
# word.toLowerCase()
    if word == "north":
        pet.moveXY(pet.pos.x, pet.pos.y + 16)
    elif word == "east":
        pet.moveXY(pet.pos.x + 12, pet.pos.y)
    elif word == "south":
        pet.moveXY(pet.pos.x, pet.pos.y - 16)
    elif word == "west":
        pet.moveXY(pet.pos.x - 12, pet.pos.y)

# Assign the event handler for the pet's "hear" event.
pet.on("hear", onHear())

```

---

<div class="post-metadata">

**Author:** ![dedreous](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dedreous/32/13849_2.png) [@dedreous](https://discourse.codecombat.com/u/dedreous)\
**Post date:** [April 19, 2020, 8:58pm UTC](https://discourse.codecombat.com/t/solved-cluttered-corridors-event-message-error/21086/2 "2020-04-19T20:58:29Z")

</div>

You do need to separate the definition of word and the conversion toLowerCase in to separate statements.

First, define the variable ‘word’. Then, convert ‘word’ by redefining it, using the .toLowerCase parameter.

---

<div class="post-metadata">

**Author:** ![xiaoming](https://avatars.discourse-cdn.com/v4/letter/x/a6a055/32.png) [@xiaoming](https://discourse.codecombat.com/u/xiaoming)\
**Post date:** [April 19, 2020, 9:03pm UTC](https://discourse.codecombat.com/t/solved-cluttered-corridors-event-message-error/21086/4 "2020-04-19T21:03:04Z")

</div>

still not working:

 ![image](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/c/cc294477cb2b09eb8df388a6f106eef79ea92fec.jpeg)

---

<div class="post-metadata">

**Author:** ![dedreous](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dedreous/32/13849_2.png) [@dedreous](https://discourse.codecombat.com/u/dedreous)\
**Post date:** [April 19, 2020, 9:15pm UTC](https://discourse.codecombat.com/t/solved-cluttered-corridors-event-message-error/21086/5 "2020-04-19T21:15:01Z")

</div>

Repost your code please…it looks good, but is obviously having probs.

---

<div class="post-metadata">

**Author:** ![xiaoming](https://avatars.discourse-cdn.com/v4/letter/x/a6a055/32.png) [@xiaoming](https://discourse.codecombat.com/u/xiaoming)\
**Post date:** [April 19, 2020, 9:17pm UTC](https://discourse.codecombat.com/t/solved-cluttered-corridors-event-message-error/21086/6 "2020-04-19T21:17:10Z")

</div>

sure thing:

```python
def onHear(event):
    word = event.message
    # Convert the word to lower case.
    word = word.toLowerCase()
    if word == "north":
        pet.moveXY(pet.pos.x, pet.pos.y + 16)
    elif word == "east":
        pet.moveXY(pet.pos.x + 12, pet.pos.y)
    elif word == "south":
        pet.moveXY(pet.pos.x, pet.pos.y - 16)
    elif word == "west":
        pet.moveXY(pet.pos.x - 12, pet.pos.y)

# Assign the event handler for the pet's "hear" event.
pet.on("hear", onHear())

```

---

<div class="post-metadata">

**Author:** ![xiaoming](https://avatars.discourse-cdn.com/v4/letter/x/a6a055/32.png) [@xiaoming](https://discourse.codecombat.com/u/xiaoming)\
**Post date:** [April 19, 2020, 9:18pm UTC](https://discourse.codecombat.com/t/solved-cluttered-corridors-event-message-error/21086/7 "2020-04-19T21:18:33Z")

</div>

hey mate, I just found the issue, I shouldn’t put"()" in the event handler ‘onHear’ at the bottom, the codes work now

---

<div class="post-metadata">

**Author:** ![xiaoming](https://avatars.discourse-cdn.com/v4/letter/x/a6a055/32.png) [@xiaoming](https://discourse.codecombat.com/u/xiaoming)\
**Post date:** [April 19, 2020, 9:19pm UTC](https://discourse.codecombat.com/t/solved-cluttered-corridors-event-message-error/21086/8 "2020-04-19T21:19:22Z")

</div>

but thanks for the help!

---

<div class="post-metadata">

**Author:** ![dedreous](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dedreous/32/13849_2.png) [@dedreous](https://discourse.codecombat.com/u/dedreous)\
**Post date:** [April 19, 2020, 9:21pm UTC](https://discourse.codecombat.com/t/solved-cluttered-corridors-event-message-error/21086/9 "2020-04-19T21:21:57Z")

</div>

heh…it’s always the silly things. I was a bit confused by this at first myself…still not sure I fully understand the logic.

However, in your final statement, you are calling onHear as if it were a function. If it were a function, then the trailing () would be required. But, as an event handler, it steps outside of the rules of a function…delete the parens ‘()’ and give it another go.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/a/a9445509d1a758c41b5ddcddc8c8e20a5dedb67f.png) [@system](https://discourse.codecombat.com/u/system)\
**Post date:** [July 29, 2020, 3:47pm UTC](https://discourse.codecombat.com/t/solved-cluttered-corridors-event-message-error/21086/10 "2020-07-29T15:47:23Z")

</div>

Closed on July 29, 2020, 3:47pm UTC

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.
