[SOLVED] Burlbole grove trouble

I have trouble woth my code. My hero always attack burls.

def shouldAttack(target):
	# return False if no target
    if not target:
        return False
    elif target == "burl":
	    return False
    # Otherwise, return True
    else:
        return True
    return True

while True:
    enemy = hero.findNearestEnemy()
    # Here we use shouldAttack() to decide if we should attack!
    # heroShouldAttack will be assigned the same value that shouldAttack() returns!
    heroShouldAttack = shouldAttack(enemy)
    if heroShouldAttack:
    	hero.attack(enemy)
    	pass
    pass

You may need an if enemy.

1 Like

It looks like you deleted the comment giving you a hint about checking the target’s type:

elif target.type == "burl": not elif target == "burl":

1 Like

Thanks for help. Now i see this comment :wink: