Help with "Cluttered Corridors"

# 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)

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.

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.

2 Likes

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.

1 Like

um what is your new code

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.

1 Like

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

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

1 Like

a question and a answer

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

1 Like

@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

so what is the code for this

we don’t post solutions here.

1 Like