Help with "Cluttered Corridors"


#1
# 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.


#2

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.


#3

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.


#4

um what is your new code


#5

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.


#6

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


#7

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


#8

a question and a answer


#9

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


#10

@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


#11

so what is the code for this


#12

we don’t post solutions here.