Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Why doesn't enemy.type work?

On Sarven Brawl I used the following code:

enemy = hero.findNearestEnemy()
    if enemy and enemy != "sand-yak":
        hero.attack(enemy)

Everything was fine except when no other enemies were around Tharin started attacking the sand-yaks. Why???

You have to do if enemy and enemy.type != "sand=yak"

The title of this thread says it all. You didn’t use enemy.type. You just used enemy != "sand-yak". Think about what the code you have is actually saying. You’ve already defined enemy and the definition of enemy will never be “sand-yak.” Try using enemy.type in your code and you should stop attacking those pesky critters.

Of course! Thank you so much!

Beat me by mere seconds. :rage:

1 Like

Also, be sure to put the topic in the correct category. In this case, it should be in ambassador instead of adventurer.

Yeah… I’m new with Discourse.

Also, when just calling enemy, you’re using an object, but you want to know the type of the object.