The hero won’t say “heal” so the pet won’t go to the top x. The hero dies then since he doesn’t have enough health.
# Your pet can help you survive until you can escape.
def onHear(event):
# event.message contains the text that was heard.
# If somebody said "Fire":
if event.message == "Fire":
# Move to the bottom X mark with pet.moveXY()
pet.moveXY(64, 16)
# Say something with pet.say()
pet.say("Fire!")
pass
# If somebody said "Heal":
elif event.message == "Heal":
# Move to the top X mark with pet.moveXY()
pet.moveXY(63, 53)
# Say something with pet.say()
pet.say("Heal!")
pass
pet.on("hear", onHear)
# You don't have to change the code below.
while True:
enemy = hero.findNearestEnemy()
if enemy:
# If an enemy is too strong.
if enemy.type == "brawler":
hero.say("Fire")
else:
hero.attack(enemy)
pass
else:
# If your hero needs healing.
if hero.health < hero.maxHealth / 2:
hero.say("Heal")
pass
This would be the troublesome code based on my analysis. This is a problem, because this is code that should not be altered.
However, it may be the fact that your hero only checks their health and if they are below the threshold if the enemy does not exist.
So, instead of your previous code, you would change it to the following.
while True:
enemy = hero.findNearestEnemy()
if enemy:
# If an enemy is too strong.
if enemy.type == "brawler":
hero.say("Fire")
else:
hero.attack(enemy)
pass
# If your hero needs healing.
if hero.health < hero.maxHealth / 2:
hero.say("Heal")
I changed it to what you said and it still won’t work:
# Your pet can help you survive until you can escape.
while True:
enemy = hero.findNearestEnemy()
if enemy:
# If an enemy is too strong.
if enemy.type == "brawler":
hero.say("Fire")
else:
hero.attack(enemy)
pass
# If your hero needs healing.
if hero.health < hero.maxHealth / 2:
hero.say("Heal")
pet.on("hear", onHear)
# You don't have to change the code below.
while True:
enemy = hero.findNearestEnemy()
if enemy:
# If an enemy is too strong.
if enemy.type == "brawler":
hero.say("Fire")
else:
hero.attack(enemy)
pass
else:
# If your hero needs healing.
if hero.health < hero.maxHealth / 2:
hero.say("Heal")
pass
This code isn’t what I told you to change it to. It still uses an else block causing it to only check the hero’s health against the threshold when the enemy does not exist. Remove the else and lower the indent a level for all the code that was in the else block. Also, remove all the pass blocks because they don’t really do anything in my experience.
# Your pet can help you survive until you can escape.
while True:
enemy = hero.findNearestEnemy()
if enemy:
# If an enemy is too strong.
if enemy.type == "brawler":
hero.say("Fire")
else:
hero.attack(enemy)
# If your hero needs healing.
if hero.health < hero.maxHealth / 2:
hero.say("Heal")
pet.on("hear", onHear)
# You don't have to change the code below.
while True:
enemy = hero.findNearestEnemy()
if enemy:
# If an enemy is too strong.
if enemy.type == "brawler":
hero.say("Fire")
else:
hero.attack(enemy)
pass
else:
# If your hero needs healing.
if hero.health < hero.maxHealth / 2:
hero.say("Heal")
pass
# Your pet can help you survive until you can escape.
while True:
enemy = hero.findNearestEnemy()
if enemy:
# If an enemy is too strong.
if enemy.type == "brawler":
hero.say("Fire")
else:
hero.attack(enemy)
# If your hero needs healing.
if hero.health < hero.maxHealth / 2:
hero.say("Heal")
pet.on("hear", onHear)
# You don't have to change the code below.
while True:
enemy = hero.findNearestEnemy()
if enemy:
# If an enemy is too strong.
if enemy.type == "brawler":
hero.say("Fire")
else:
hero.attack(enemy)
pass
# If your hero needs healing.
if hero.health < hero.maxHealth / 2:
hero.say("Heal")
pass