# This variable is used for counting ogres. defeatedOgres = 0 # This loop is executed while defeatedOgres is less than 6. while defeatedOgres < 6: enemy = hero.findNearestEnemy() if enemy: hero.attack(enemy) defeatedOgres += 1 else: hero.say("Ogres!") # Move to the right side of the map. hero.moveXY(65, 53) # This loop is executed while you have less than 30 gold. while hero.gold < 30: # Find and collect coins. hero.findNearestItem() if item and item.type == "coin": hero.findNearestItem() targetpos = coin.pos hero.move(target.pos) # Remove this say() message. hero.say("I should gather coins!") # Move to the exit. hero.moveXY(76, 32)
it is saying that “item is not defined” when I have a hero.findNearestItem() statement.