# Help with "Cluttered Corridors"

**URL:** <https://discourse.codecombat.com/t/help-with-cluttered-corridors/9732>\
**Category:** Uncategorized\
**Created:** [November 25, 2016, 4:55am UTC](https://discourse.codecombat.com/t/help-with-cluttered-corridors/9732 "2016-11-25T04:55:05Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gelsh](https://avatars.discourse-cdn.com/v4/letter/g/8491ac/32.png) [@Gelsh](https://discourse.codecombat.com/u/Gelsh)\
**Post date:** [November 25, 2016, 4:55am UTC](https://discourse.codecombat.com/t/help-with-cluttered-corridors/9732/1 "2016-11-25T04:55:05Z")

</div>

> ```python
> # Help the pet find the exit.
> 
> ```

> def onHear(event):  
> jumble = event.message  
> # Convert the word to lower case.  
> word = jumble.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.
> 
> while True:  
> pet.on(“hear”, onHear)
> 
> ```python
> 
> ```

 ![](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/3/3e381aaf53c7cf8f563017e32caf1cca81cf3152.jpg)

I can’t be sure because I haven’t learned all the pet related commands, but the code seems sound. If I was to guess, I would say the statue might say the first direction for a few ticks too long, or the next statue not soon enough, as the pet’s code continues with the original command.

Also, my apologies if its a simple error on my part.

---

<div class="post-metadata">

**Author:** ![Bryukh](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/bryukh/32/19597_2.png) [@Bryukh](https://discourse.codecombat.com/u/Bryukh)\
**Post date:** [November 25, 2016, 6:41am UTC](https://discourse.codecombat.com/t/help-with-cluttered-corridors/9732/2 "2016-11-25T06:41:22Z")

</div>

> [@Gelsh](#):
>
> while True:  
> pet.on(“hear”, onHear)

You add an event handler for each frame. So as the result for the first phrase launch a lot of handlers and instead once you pet move many steps.

---

<div class="post-metadata">

**Author:** ![Gelsh](https://avatars.discourse-cdn.com/v4/letter/g/8491ac/32.png) [@Gelsh](https://discourse.codecombat.com/u/Gelsh)\
**Post date:** [November 25, 2016, 7:02am UTC](https://discourse.codecombat.com/t/help-with-cluttered-corridors/9732/3 "2016-11-25T07:02:25Z")

</div>

Alright, thank you. I’m going through older areas to play other levels in hopes of finding the answer, but how would I distinguish each event? I guess I was under the impression that the level would govern when to change direction.

Edit: Sorry if this is unclear. How do I ask it to stop and listen for the next event? Rather than spamming in a while-loop?

Edit 2: I’m sorry, I didn’t understand that the pet continuously “listens.” I thought I had to tell him to listen to each event and run it through the function. —I’m too tired to be coding— Simple answer, no loop.

---

<div class="post-metadata">

**Author:** ![mastercoder827](https://avatars.discourse-cdn.com/v4/letter/m/b5a626/32.png) [@mastercoder827](https://discourse.codecombat.com/u/mastercoder827)\
**Post date:** [March 3, 2017, 7:08am UTC](https://discourse.codecombat.com/t/help-with-cluttered-corridors/9732/4 "2017-03-03T07:08:47Z")

</div>

um what is your new code

---

<div class="post-metadata">

**Author:** ![Bryukh](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/bryukh/32/19597_2.png) [@Bryukh](https://discourse.codecombat.com/u/Bryukh)\
**Post date:** [March 3, 2017, 7:20am UTC](https://discourse.codecombat.com/t/help-with-cluttered-corridors/9732/5 "2017-03-03T07:20:16Z")

</div>

> [@Gelsh](#):
>
> How do I ask it to stop and listen for the next event?

It will be explained later. But for “hear” event you don’t need `while`. The event handler is called each time when the pet hears something.

---

<div class="post-metadata">

**Author:** ![mastercoder827](https://avatars.discourse-cdn.com/v4/letter/m/b5a626/32.png) [@mastercoder827](https://discourse.codecombat.com/u/mastercoder827)\
**Post date:** [March 4, 2017, 2:57am UTC](https://discourse.codecombat.com/t/help-with-cluttered-corridors/9732/6 "2017-03-04T02:57:49Z")

</div>

so when "hear it hears it and when are you explaning

---

<div class="post-metadata">

**Author:** ![Bryukh](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/bryukh/32/19597_2.png) [@Bryukh](https://discourse.codecombat.com/u/Bryukh)\
**Post date:** [March 5, 2017, 12:57pm UTC](https://discourse.codecombat.com/t/help-with-cluttered-corridors/9732/7 "2017-03-05T12:57:22Z")

</div>

Was it a question?  
Sorry, but I didn’t get you.

---

<div class="post-metadata">

**Author:** ![mastercoder827](https://avatars.discourse-cdn.com/v4/letter/m/b5a626/32.png) [@mastercoder827](https://discourse.codecombat.com/u/mastercoder827)\
**Post date:** [March 5, 2017, 10:16pm UTC](https://discourse.codecombat.com/t/help-with-cluttered-corridors/9732/8 "2017-03-05T22:16:22Z")

</div>

a question and a answer

---

<div class="post-metadata">

**Author:** ![Bryukh](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/bryukh/32/19597_2.png) [@Bryukh](https://discourse.codecombat.com/u/Bryukh)\
**Post date:** [March 6, 2017, 4:30am UTC](https://discourse.codecombat.com/t/help-with-cluttered-corridors/9732/9 "2017-03-06T04:30:05Z")

</div>

Ok. Which one is a question and which one is an answer? Could you please punctuation marks (. , ?) ?

---

<div class="post-metadata">

**Author:** ![\_TD\_RodYT](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/_td_rodyt/32/6285_2.png) [@\_TD\_RodYT](https://discourse.codecombat.com/u/_TD_RodYT)\
**Post date:** [March 6, 2017, 4:22pm UTC](https://discourse.codecombat.com/t/help-with-cluttered-corridors/9732/10 "2017-03-06T16:22:42Z")

</div>

@mastercoder827 Yes. As long as you use the pet.on(“hear”, onHear), whenever your hero or an NPC non playable character, talks, it will trigger the function. No need for a while loop

---

<div class="post-metadata">

**Author:** ![mastercoder827](https://avatars.discourse-cdn.com/v4/letter/m/b5a626/32.png) [@mastercoder827](https://discourse.codecombat.com/u/mastercoder827)\
**Post date:** [March 8, 2017, 10:19am UTC](https://discourse.codecombat.com/t/help-with-cluttered-corridors/9732/11 "2017-03-08T10:19:07Z")

</div>

so what is the code for this

---

<div class="post-metadata">

**Author:** ![Bryukh](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/bryukh/32/19597_2.png) [@Bryukh](https://discourse.codecombat.com/u/Bryukh)\
**Post date:** [March 8, 2017, 12:46pm UTC](https://discourse.codecombat.com/t/help-with-cluttered-corridors/9732/12 "2017-03-08T12:46:23Z")

</div>

we don’t post solutions here.
