[Solved] Help With Weakest Quickest


#1

Hi,
i’m having a lot of trouble with levels that uses enemy.health or coin.value, Can someone please explain why this is happening?


,My Code:

# Defeat shamans to survive.

# The function find the weakest enemy.
def findWeakestEnemy():
    enemies = hero.findEnemies()
    weakest = None
    leastHealth = 99999
    enemyIndex = 0
    enemies = hero.findEnemies()
    # Loop through enemies:
    while enemyIndex < len(enemies):
        enemy = enemies[enemyIndex]
        # If an enemy's health is less than leastHealth:
        if enemy.health < leastHealth:    
            # Make it the weakest 
            enemy = weakest
            # and set leastHealth to its health.
            leastHealth = enemy.health
        enemyIndex += 1
    return weakest

while True:
    # Find the weakest enemy with the function:
    weakestShaman = findWeakestEnemy()
    # If the weakest enemy here:
    if weakestShaman:
        # Attack it!
        hero.attack(weakestShaman)


#2

Do weakest=enemy :wink: And weakestShaman=weakest Since there is no such thing as find weakest enemy


#3

Thank you, it worked by replacing enemy = weakest with

weakest = enemy 

But i didn’t Understand why.


#4

Since the other way, it means that the weakest is enemy, but not all enemies are weakest so in the other way the current enemy is the weakest


#5

I’ve never seen this level before. Is this a new release?


#6

Nope, its a desert level, a pretty old one


#7

Okay cuz I’ve never seen the level in the desert before. When I go to desert it never had an arrow pointing at the level until now.

I thought I finished all non-subscriber code combat levels, until today oof


#8

RU a sub or not? Just curious. :wink:


#9

No I’m not a sub :C

Yeah I know it’s sad. But subscribing wouldn’t let me learn new concepts which is why I didn’t subscribe