Self.findenemies() returns a door object!


#1

in Cavern Survival i am running this code:

loop:
    enemies = self.findEnemies()
    enemy = self.findNearest(enemies)
    if enemy:
        if self.isReady("cleave"):
            self.cleave(enemy)
        else:
            self.attack(enemy)

However the hero attacks a door! It would appear that the self.findenemies() function thinks door are enemies. Is this intended behaviour?

Thanks.


#2

I think so, as you can attack them. You should be able to avoid them using their names or types.


#3

It is intended. you can attack them, they are an enemy they even have a team assigned to them


#4

How can I find out the door’s name or type then? I tried:
hero.say(hero.find.NearestEnemy)
(hero.say is sort of intend for use as print function?), but it only returns an incomplete gibberish (i.e. if the door’s name or type is mentioned in the output, the game is snipping it/not showing it.


#5

As for Cavern Survival’s doors, the type is “door” and names are “West Door” and “East Door”.

With clicking on them) Names and type shown in the bottom of the level.


#6

Did you mean hero.findNearestEnemy() instead of hero.find.NearestEnemy()?


#7

Actually, yes - thanks for the tip.


#8

So to address the elephant in the room: How to exclude that darned door from the attack?


#9

Well, using enemy.type and operators and and != in def killEmAll() function may be a good idea?


#10

not sure if this will work, and it will probably not, but use

enemy = hero.findNearestEnemy()
enemy = enemy + enemy.type != "door"

#11

I think you can’t add strings


#12

You could just do something like

enemy = hero.findNearestEnemy()
if enemy:
    if enemy.type != "door":
        hero.attack(enemy)

#13

Yeah, but then the hero will sit around there doing nothing, until another enemy comes.


#14

I think it may depend on the glasses the hero uses?


#15

It only attacks nearest enemy: it will not act until door isn’t nearest. enemy.