Can someone tell me what is this error? Codecombat


Mmmmmm I tried my best…
i think the website is faulty.
What is UAdd??
I searched google and there was just no result.
The only thing i say is some Arabic website which i don’t even understand.
Can someone help me?

The level is the dessert Brittle Morale

Welcome to the CodeCombat discourse @Tipic_a. :tada:
I’ve found the/one of the errors.
You’ve put:

enemyIndex =+ 1

That’s incorrect. I’ve also come across the error: Unknown unary operator UAdd. Because it contains the word “add” it would make sense it would be talking about the error I found.
I can see that the rest of your function is correct. So once you’ve fixed that, it should work.
:lion: :lion: :lion:

3 Likes

i don’t know if im being stupid or not but here is my code

# You have one arrow. Make it count!

# This should return the enemy with the most health.
def findStrongestEnemy(enemies):
    strongest = None
    strongestHealth = 0
    enemyIndex = 0
    # While enemyIndex is less than the length of enemies:
    while enemyIndex < len(enemies):
        enemy = hero.findNearestEnemy
        # Set an enemy variable to enemies[enemyIndex]
        enemies[enemyIndex] = enemy
        # If enemy.health is greater than strongestHealth
        if enemy.health > strongestHealth:
            # Set `strongest` to enemy
            # Set strongestHealth to enemy.health
            strongestHealth = enemy.health
            strongest = enemy
        # Increment enemyIndex
        enemyIndex += 1

    return strongest

enemies = hero.findEnemies()
leader = findStrongestEnemy(enemies)
if leader:
    hero.say(leader)

thanks.

so did solve it if yes, yay, else, nooo

You’ve almost got it. The problem is that you are defining enemy and enemies incorrectly. You first define enemies at the bottom of the code; you then pass this object to the findStrongestEnemy function when you define ‘leader’. In the function, you start iterating through the array ‘enemies’…this is all good.

However, you then define enemy as the closest enemy…this will always be just one enemy and very likely the same one every time. Also, you have your enemy definition transposed. See the comments:

    while enemyIndex < len(enemies):
        enemy = hero.findNearestEnemy ### delete this entire line
        # Set an enemy variable to enemies[enemyIndex]
        enemies[enemyIndex] = enemy ### these are backwards
        # If enemy.health is greater than strongestHealth
        if enemy.health > strongestHealth:
            # Set `strongest` to enemy
            # Set strongestHealth to enemy.health
            strongestHealth = enemy.health
            strongest = enemy
        # Increment enemyIndex
        enemyIndex += 1

    return strongest

Everything else looks good :slightly_smiling_face:

I dont do python but i wanna learn it one day

well its easy for me i think you will like it, Jeremy_Yu, and thanks for the help dedreous… again

I look forward to learning