Probleme avec mon code sur Backwoods Brawl

J’ai tenté de faire un code un peu plus complexe, mais j’ai un souci avec mon code. J’aimerai qu’on m’aiguille. Merci a vous. C’est en language Python.

<while True:
enemy = hero.findNearestEnemy()
gflag = hero.findFlag(“green”)
bflag = hero.findFlag(“black”)

if enemy:
    
    if enemy >5:
        if hero.canCast("chain-lightning", enemy):
            hero.cast("chain-lightning", enemy)
        if hero.canCast("invisibility"):
            hero.cast("invisibility", hero)
            
    if enemy.type == "ogre":
        if hero.isReady("throw") and hero.distanceTo("ogre") < hero.throwRange:
            hero.throw("ogre")
    
    if gflag:
        hero.pickUpFlag(gflag)
    
    if bflag:
        hero.moveXY(bflag.pos.x, bflag.pos.y)
        hero.buildXY("caltrops", bflag.pos.x, bflag.pos.y)

else:
    hero.attack(enemy)

quel est le problème

if enemy.type == “ogre”:
if hero.isReady(“throw”) and hero.distanceTo(“ogre”) < hero.throwRange:
hero.throw(“ogre”)

on me dit que “ogre” n’est pas un argument
je vais essayer de mettre une photo pour montrer l’erreur

il ne sait pas ce qu’est “orge”

Salut @Kifyu. Pour cet problem, comme Chihya_957 a dit, on doit utiliser le variable “enemy”, parce que “ogre” est juste un “string” (c’est a dire, le text en “”). Ce n’est pas un truc qu’on peut utiliser avec hero.distanceTo() car ce n’est pas exact. Il peut etre tout les “ogres” dans cet niveau.
Pardon pour mon Français mal, je l’apprends maintenant.
Danny

Comment je pourrais faire pour que mon hero attaque “throw” ? Mais seulement les ogres. Je n’arrive pas a retrouver l’etape pour attaquer seulement un type d’unité. Pour le moment, j’ai enlevé la ligne qui correspond a cela.
Je vous remercie pour votre aide.

à la place de chaque “ogre” il faut que tu mettes: enemy

oui mais j’aurai aimé qu’il n’utilise le “throw” que sur les ogres. C’étais surtout pour m’entrainer a differencier les troupes et utiliser le “throw”…
:rofl: :sweat_smile: :joy:

And, differentiate you did. However, the syntax you are attempting is not going to work. Look at the first line I quoted…you have defined ‘enemy’ and determined its type. Now, you need to attack…the object of the attack is ‘ogre’, which is already defined as ‘enemy’. Hence, you need:

hero.distanceTo(enemy)

…you already know you are attacking only an ‘ogre’, otherwise, this statement would not even be executing.

Thank you. I will try

btw, don’t forget…the same applies to your hero.throw statement. There is no ‘ogre’, only the ‘enemy’.