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())
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())
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.