I need help with my code

My troops attack everyone even though I said only brawler

1 Like

Your OR: ||
should be an AND: &&
as such:
enemy && enemy.type == "brawler" && hero.distanceTo(enemy) < 50

As it reads right now, you’re saying if it’s a brawler or it’s ANYTHING within 50 units of the player, say “fire”

1 Like

Thanks for your help, I already fixed, sorry for keeping it up

1 Like

No problem. Glad you fixed it!

1 Like

Can yu help me here?

1 Like

That code works fine for me, but I have about 3x more health. I’ll try it with less in a moment.

What’s the problem you’re having with it?

Edit:
My bad. You have an extra curly brace right under hero.attack(enemy);

1 Like

He doesn’t attack all the enemies

1 Like

Ah, I see it now. Edited my post.

1 Like

It’s not extra look at screenshot

1 Like

You’re right, but it should be placed underneath hero.move(item.pos);

1 Like

Thanks I got it :boy:

2 Likes

I gotta go, bye, oh and if you wanna join clan, here is the link https://codecombat.com/clans/572e74fffc0cb1a80176a206
we need people like you.

1 Like