Issues cannot read property : Beginner

Hello ,

I have started to learn the Programmation so it’s probably a stupid mistake ^^’.
So I have created a function “countEnnemyClose()” it worked when I used it in the code.
But when I used it in another function I have had “Fix Your Code Line 18 TypeError: Cannot read property ‘value’ of undefined”.

can anybody help me with my problem


while True:
    #enemy = countEnnemyClose()


def findAndAttack(close) :
    enemy = hero.findNearestEnemy()
    close = countEnnemyClose()
    if enemy:
        distance = hero.distanceTo(enemy)
        if distance > 20:
        if distance < 10:
            if close >= 3 :
                if hero.isReady("cleave"):
                if hero.isReady("bash"):

def countEnnemyClose() :
    enemies = hero.findEnemies()
    count = 0
    for enemy in enemies:
        distance = hero.distanceTo(enemy)
        if distance < 12:
            count += 1
    return count

I think you can’t define a subsequent function first. First you define a function which takes its data from the function that isn’t defined yet. But beginner here, too :wink:

And btw why do you want to attack when the distance is so big and to shield when enemies are close? Was this really what the task wanted?

what is the name of this level?

The code isn’t finished yet (of course), but the idea is to kill archers before and use cleave only if they are 3 enemies close to me. For the shield I just put there, maybe isn’t a good idea.

How can I define a subsequent function?

Munkey Shynes the level name is Backwoods Brawl :slight_smile:

I think what kuska is saying is to reverse the order of your functions. I don’t know if that makes a difference though. Although the usual format is to define your functions first and then call them in the code. Your code is first and then you define the functions.


It’s Working! I change the order ^^ I knew it it was a stupid mistake. Thank you very much

1 Like