Chain lightning wont work crrectly(javascript)

while (true) {
    var green = hero.findFlag("green");
    var black = hero.findFlag("black");
    var nearest = hero.findNearestEnemy();
    if (green) {
        hero.pickUpFlag(green);
    } else if (black && hero.isReady("cleave")) {
        hero.pickUpFlag(black);
        // Cleave!
        hero.cleave(nearest);
    } 
     if (hero.canCast("chain-lightning"), nearest && nearest.health > 0){
        hero.cast("chain-lightning", nearest);
    }
    if (hero.isReady("bash") && nearest && nearest.health > 0){
        hero.bash(nearest);
    }
    else if (nearest && nearest.health > 0){
        // Attack!
        hero.attack(nearest);
        hero.shield();
    }
   
}

my hero can only cast chain lightning once but doesn’t do anything after. how can i fix?

Well, you have several If statements without an else, and while this shouldn’t really harm your code, it’s pretty sloppy. I reccomend trying to clear it up a little bit, see if that helps.

You have a comma after hero.canCast("chain-lightning"), where there should be && instead.

1 Like

Ah, he’s right, good catch. Didn’t see that.

thanks works fine now