My code is correct but every time I pass over a coin that isn’t labeled “item” it doesn’t count toward my “totalGold”… how do I fix that??
# This function allows to fight until the certain time
# and report about defeated enemies.
def fightAndReport(untilTime):
defeated = 0
while True:
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
if enemy.health <= 0:
defeated += 1
if hero.time > untilTime:
break
hero.moveXY(59, 33)
hero.say(defeated)
# Fight 15 seconds and tell Naria how many enemies you defeated.
fightAndReport(15)
# Collect coins until the clock reaches 30 seconds.
def collectCoins(untilTime):
totalGold = 0
while True:
item = hero.findNearestItem()
if item:
hero.moveXY(item.pos.x, item.pos.y)
totalGold += item.value
if hero.time > untilTime:
break
hero.moveXY(59, 33)
hero.say(totalGold)
collectCoins(30)
fightAndReport(45)
