I need help with my code


#1

My troops attack everyone even though I said only brawler


#2

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”


#3

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


#4

No problem. Glad you fixed it!


#5

Can yu help me here?


#6

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);


#7

He doesn’t attack all the enemies


#8

Ah, I see it now. Edited my post.


#9

It’s not extra look at screenshot


#10

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


#11

Thanks I got it :boy:


#12

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.